Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -1,6 +1,7 @@
|
|
1 |
import os
|
2 |
-
import csv
|
3 |
import streamlit as st
|
|
|
|
|
4 |
from langchain_community.vectorstores import FAISS
|
5 |
from langchain_community.embeddings import HuggingFaceEmbeddings
|
6 |
from langchain_huggingface import HuggingFaceEndpoint
|
@@ -67,38 +68,30 @@ qa = RetrievalQA.from_chain_type(
|
|
67 |
chain_type_kwargs={"prompt": prompt},
|
68 |
)
|
69 |
|
70 |
-
import psycopg2
|
71 |
-
import streamlit as st
|
72 |
-
from datetime import datetime
|
73 |
-
import os
|
74 |
-
|
75 |
# PostgreSQL connection setup using secrets from Hugging Face Spaces
|
76 |
def create_connection():
|
77 |
-
|
78 |
host=os.getenv("DB_HOST"),
|
79 |
database=os.getenv("DB_NAME"),
|
80 |
user=os.getenv("DB_USER"),
|
81 |
password=os.getenv("DB_PASSWORD"),
|
82 |
port=os.getenv("DB_PORT")
|
83 |
)
|
84 |
-
|
85 |
-
|
86 |
-
|
87 |
-
|
88 |
-
|
89 |
-
|
90 |
-
|
91 |
-
|
92 |
-
|
93 |
-
|
94 |
-
)
|
95 |
-
''')
|
96 |
-
conn.commit()
|
97 |
|
98 |
# Streamlit interface with improved aesthetics
|
99 |
st.set_page_config(page_title="Alter-IA Chat", page_icon="π€")
|
100 |
|
101 |
-
# Define function to handle user input and display chatbot response
|
102 |
def chatbot_response(user_input):
|
103 |
response = qa.run(user_input)
|
104 |
return response
|
@@ -168,14 +161,14 @@ if submit_button:
|
|
168 |
<div class="star-rating">
|
169 |
<input type="radio" id="5-stars" name="rating" value="5"><label for="5-stars">β
</label>
|
170 |
<input type="radio" id="4-stars" name="rating" value="4"><label for="4-stars">β
</label>
|
171 |
-
<input type="radio" id="3-stars" name="rating" value="3"
|
172 |
<input type="radio" id="2-stars" name="rating" value="2"><label for="2-stars">β
</label>
|
173 |
<input type="radio" id="1-star" name="rating" value="1"><label for="1-star">β
</label>
|
174 |
</div>
|
175 |
"""
|
176 |
st.markdown(rating_html, unsafe_allow_html=True)
|
177 |
|
178 |
-
#
|
179 |
rating = st.text_input("Selected Rating:", value="3", key="rating_input", label_visibility="hidden")
|
180 |
|
181 |
comment = st.text_area("Your Comment:")
|
@@ -188,14 +181,10 @@ if submit_button:
|
|
188 |
st.warning("β Please provide a comment.")
|
189 |
else:
|
190 |
st.success("Thank you for your feedback!")
|
191 |
-
|
192 |
# Store feedback in PostgreSQL
|
193 |
conn = create_connection()
|
194 |
-
|
195 |
-
timestamp = datetime.now().strftime("%Y-%m-%d %H:%M:%S")
|
196 |
-
cur.execute('INSERT INTO feedback (timestamp, rating, comment) VALUES (%s, %s, %s)',
|
197 |
-
(timestamp, int(rating), comment))
|
198 |
-
conn.commit()
|
199 |
conn.close()
|
200 |
|
201 |
else:
|
|
|
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
|
|
|
68 |
chain_type_kwargs={"prompt": prompt},
|
69 |
)
|
70 |
|
|
|
|
|
|
|
|
|
|
|
71 |
# PostgreSQL connection setup using secrets from Hugging Face Spaces
|
72 |
def create_connection():
|
73 |
+
return psycopg2.connect(
|
74 |
host=os.getenv("DB_HOST"),
|
75 |
database=os.getenv("DB_NAME"),
|
76 |
user=os.getenv("DB_USER"),
|
77 |
password=os.getenv("DB_PASSWORD"),
|
78 |
port=os.getenv("DB_PORT")
|
79 |
)
|
80 |
+
|
81 |
+
def insert_feedback(conn, rating, comment):
|
82 |
+
try:
|
83 |
+
with conn.cursor() as cur:
|
84 |
+
timestamp = datetime.now().strftime("%Y-%m-%d %H:%M:%S")
|
85 |
+
cur.execute('INSERT INTO feedback (timestamp, rating, comment) VALUES (%s, %s, %s)',
|
86 |
+
(timestamp, int(rating), comment))
|
87 |
+
conn.commit()
|
88 |
+
st.write("Feedback inserted successfully.")
|
89 |
+
except Exception as e:
|
90 |
+
st.write(f"Error inserting feedback: {e}")
|
|
|
|
|
91 |
|
92 |
# Streamlit interface with improved aesthetics
|
93 |
st.set_page_config(page_title="Alter-IA Chat", page_icon="π€")
|
94 |
|
|
|
95 |
def chatbot_response(user_input):
|
96 |
response = qa.run(user_input)
|
97 |
return response
|
|
|
161 |
<div class="star-rating">
|
162 |
<input type="radio" id="5-stars" name="rating" value="5"><label for="5-stars">β
</label>
|
163 |
<input type="radio" id="4-stars" name="rating" value="4"><label for="4-stars">β
</label>
|
164 |
+
<input type="radio" id="3-stars" name="rating" value="3"><label for="3-stars">β
</label>
|
165 |
<input type="radio" id="2-stars" name="rating" value="2"><label for="2-stars">β
</label>
|
166 |
<input type="radio" id="1-star" name="rating" value="1"><label for="1-star">β
</label>
|
167 |
</div>
|
168 |
"""
|
169 |
st.markdown(rating_html, unsafe_allow_html=True)
|
170 |
|
171 |
+
# Use a hidden input to capture the selected rating
|
172 |
rating = st.text_input("Selected Rating:", value="3", key="rating_input", label_visibility="hidden")
|
173 |
|
174 |
comment = st.text_area("Your Comment:")
|
|
|
181 |
st.warning("β Please provide a comment.")
|
182 |
else:
|
183 |
st.success("Thank you for your feedback!")
|
184 |
+
|
185 |
# Store feedback in PostgreSQL
|
186 |
conn = create_connection()
|
187 |
+
insert_feedback(conn, rating, comment)
|
|
|
|
|
|
|
|
|
188 |
conn.close()
|
189 |
|
190 |
else:
|