Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,7 +1,7 @@
|
|
| 1 |
import os
|
|
|
|
| 2 |
import streamlit as st
|
| 3 |
from datetime import datetime
|
| 4 |
-
import psycopg2
|
| 5 |
from langchain_community.vectorstores import FAISS
|
| 6 |
from langchain_community.embeddings import HuggingFaceEmbeddings
|
| 7 |
from langchain_huggingface import HuggingFaceEndpoint
|
|
@@ -85,9 +85,9 @@ def insert_feedback(conn, rating, comment):
|
|
| 85 |
cur.execute('INSERT INTO feedback (timestamp, rating, comment) VALUES (%s, %s, %s)',
|
| 86 |
(timestamp, int(rating), comment))
|
| 87 |
conn.commit()
|
| 88 |
-
st.
|
| 89 |
except Exception as e:
|
| 90 |
-
st.
|
| 91 |
|
| 92 |
# Streamlit interface with improved aesthetics
|
| 93 |
st.set_page_config(page_title="Alter-IA Chat", page_icon="🤖")
|
|
@@ -146,7 +146,6 @@ st.markdown('<p class="centered-orange-text">"Votre Réponse à Chaque Défi Mé
|
|
| 146 |
user_input = st.text_input("You:", "")
|
| 147 |
submit_button = st.button("Ask 📨")
|
| 148 |
|
| 149 |
-
|
| 150 |
if submit_button:
|
| 151 |
if user_input.strip() != "":
|
| 152 |
bot_response = chatbot_response(user_input)
|
|
@@ -156,37 +155,43 @@ if submit_button:
|
|
| 156 |
# Add rating and comment section
|
| 157 |
st.markdown("---")
|
| 158 |
st.markdown("#### Rate the Response:")
|
| 159 |
-
|
| 160 |
-
#
|
| 161 |
-
|
| 162 |
-
|
| 163 |
-
|
| 164 |
-
<
|
| 165 |
-
|
| 166 |
-
|
| 167 |
-
|
| 168 |
-
|
| 169 |
-
|
| 170 |
-
|
| 171 |
-
|
| 172 |
-
|
| 173 |
-
|
| 174 |
-
|
| 175 |
-
|
| 176 |
-
|
| 177 |
-
|
| 178 |
-
|
| 179 |
-
|
| 180 |
-
|
| 181 |
-
|
| 182 |
-
|
| 183 |
-
|
| 184 |
-
|
| 185 |
-
|
| 186 |
-
|
| 187 |
-
|
| 188 |
-
|
| 189 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 190 |
|
| 191 |
else:
|
| 192 |
st.warning("⚠ Please enter a message.")
|
|
|
|
| 1 |
import os
|
| 2 |
+
import psycopg2
|
| 3 |
import streamlit as st
|
| 4 |
from datetime import datetime
|
|
|
|
| 5 |
from langchain_community.vectorstores import FAISS
|
| 6 |
from langchain_community.embeddings import HuggingFaceEmbeddings
|
| 7 |
from langchain_huggingface import HuggingFaceEndpoint
|
|
|
|
| 85 |
cur.execute('INSERT INTO feedback (timestamp, rating, comment) VALUES (%s, %s, %s)',
|
| 86 |
(timestamp, int(rating), comment))
|
| 87 |
conn.commit()
|
| 88 |
+
st.success("Feedback inserted successfully.")
|
| 89 |
except Exception as e:
|
| 90 |
+
st.error(f"Error inserting feedback: {e}")
|
| 91 |
|
| 92 |
# Streamlit interface with improved aesthetics
|
| 93 |
st.set_page_config(page_title="Alter-IA Chat", page_icon="🤖")
|
|
|
|
| 146 |
user_input = st.text_input("You:", "")
|
| 147 |
submit_button = st.button("Ask 📨")
|
| 148 |
|
|
|
|
| 149 |
if submit_button:
|
| 150 |
if user_input.strip() != "":
|
| 151 |
bot_response = chatbot_response(user_input)
|
|
|
|
| 155 |
# Add rating and comment section
|
| 156 |
st.markdown("---")
|
| 157 |
st.markdown("#### Rate the Response:")
|
| 158 |
+
|
| 159 |
+
# Use Streamlit form for feedback
|
| 160 |
+
with st.form(key='feedback_form'):
|
| 161 |
+
# Custom star rating HTML
|
| 162 |
+
rating_html = """
|
| 163 |
+
<div class="star-rating">
|
| 164 |
+
<input type="radio" id="5-stars" name="rating" value="5"><label for="5-stars">★</label>
|
| 165 |
+
<input type="radio" id="4-stars" name="rating" value="4"><label for="4-stars">★</label>
|
| 166 |
+
<input type="radio" id="3-stars" name="rating" value="3" checked><label for="3-stars">★</label>
|
| 167 |
+
<input type="radio" id="2-stars" name="rating" value="2"><label for="2-stars">★</label>
|
| 168 |
+
<input type="radio" id="1-star" name="rating" value="1"><label for="1-star">★</label>
|
| 169 |
+
</div>
|
| 170 |
+
<input type="hidden" id="selected-rating" name="rating" value="3">
|
| 171 |
+
<script>
|
| 172 |
+
const ratingLabels = document.querySelectorAll('.star-rating label');
|
| 173 |
+
ratingLabels.forEach(label => {
|
| 174 |
+
label.addEventListener('click', () => {
|
| 175 |
+
document.getElementById('selected-rating').value = label.previousElementSibling.value;
|
| 176 |
+
});
|
| 177 |
+
});
|
| 178 |
+
</script>
|
| 179 |
+
"""
|
| 180 |
+
st.markdown(rating_html, unsafe_allow_html=True)
|
| 181 |
+
|
| 182 |
+
rating = st.text_input("Selected Rating:", value="3", key="rating_input", label_visibility="hidden")
|
| 183 |
+
comment = st.text_area("Your Comment:")
|
| 184 |
+
|
| 185 |
+
submit_feedback_button = st.form_submit_button("Submit Feedback")
|
| 186 |
+
|
| 187 |
+
if submit_feedback_button:
|
| 188 |
+
if comment.strip() == "":
|
| 189 |
+
st.warning("⚠ Please provide a comment.")
|
| 190 |
+
else:
|
| 191 |
+
# Store feedback in PostgreSQL
|
| 192 |
+
conn = create_connection()
|
| 193 |
+
insert_feedback(conn, rating, comment)
|
| 194 |
+
conn.close()
|
| 195 |
|
| 196 |
else:
|
| 197 |
st.warning("⚠ Please enter a message.")
|