Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -78,14 +78,16 @@ def create_connection():
|
|
| 78 |
port=os.getenv("DB_PORT")
|
| 79 |
)
|
| 80 |
|
| 81 |
-
def insert_feedback(
|
| 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 |
-
|
|
|
|
| 89 |
except Exception as e:
|
| 90 |
st.error(f"Error inserting feedback: {e}")
|
| 91 |
return False
|
|
@@ -159,28 +161,7 @@ if submit_button:
|
|
| 159 |
|
| 160 |
# Use Streamlit form for feedback
|
| 161 |
with st.form(key='feedback_form'):
|
| 162 |
-
|
| 163 |
-
rating_html = """
|
| 164 |
-
<div class="star-rating">
|
| 165 |
-
<input type="radio" id="5-stars" name="rating" value="5"><label for="5-stars">★</label>
|
| 166 |
-
<input type="radio" id="4-stars" name="rating" value="4"><label for="4-stars">★</label>
|
| 167 |
-
<input type="radio" id="3-stars" name="rating" value="3" checked><label for="3-stars">★</label>
|
| 168 |
-
<input type="radio" id="2-stars" name="rating" value="2"><label for="2-stars">★</label>
|
| 169 |
-
<input type="radio" id="1-star" name="rating" value="1"><label for="1-star">★</label>
|
| 170 |
-
</div>
|
| 171 |
-
<input type="hidden" id="selected-rating" name="rating" value="3">
|
| 172 |
-
<script>
|
| 173 |
-
const ratingLabels = document.querySelectorAll('.star-rating label');
|
| 174 |
-
ratingLabels.forEach(label => {
|
| 175 |
-
label.addEventListener('click', () => {
|
| 176 |
-
document.getElementById('selected-rating').value = label.previousElementSibling.value;
|
| 177 |
-
});
|
| 178 |
-
});
|
| 179 |
-
</script>
|
| 180 |
-
"""
|
| 181 |
-
st.markdown(rating_html, unsafe_allow_html=True)
|
| 182 |
-
|
| 183 |
-
rating = st.text_input("Selected Rating:", value="3", key="rating_input", label_visibility="hidden")
|
| 184 |
comment = st.text_area("Your Comment:")
|
| 185 |
|
| 186 |
submit_feedback_button = st.form_submit_button("Submit Feedback")
|
|
@@ -190,10 +171,10 @@ if submit_button:
|
|
| 190 |
st.warning("⚠ Please provide a comment.")
|
| 191 |
else:
|
| 192 |
# Store feedback in PostgreSQL
|
| 193 |
-
|
| 194 |
-
if insert_feedback(conn, rating, comment):
|
| 195 |
st.success("Thank you for your feedback!")
|
| 196 |
-
|
|
|
|
| 197 |
|
| 198 |
else:
|
| 199 |
st.warning("⚠ Please enter a message.")
|
|
|
|
| 78 |
port=os.getenv("DB_PORT")
|
| 79 |
)
|
| 80 |
|
| 81 |
+
def insert_feedback(rating, comment):
|
| 82 |
try:
|
| 83 |
+
conn = create_connection()
|
| 84 |
with conn.cursor() as cur:
|
| 85 |
timestamp = datetime.now().strftime("%Y-%m-%d %H:%M:%S")
|
| 86 |
cur.execute('INSERT INTO feedback (timestamp, rating, comment) VALUES (%s, %s, %s)',
|
| 87 |
(timestamp, int(rating), comment))
|
| 88 |
conn.commit()
|
| 89 |
+
conn.close()
|
| 90 |
+
return True
|
| 91 |
except Exception as e:
|
| 92 |
st.error(f"Error inserting feedback: {e}")
|
| 93 |
return False
|
|
|
|
| 161 |
|
| 162 |
# Use Streamlit form for feedback
|
| 163 |
with st.form(key='feedback_form'):
|
| 164 |
+
rating = st.select_slider("Rating:", options=[1, 2, 3, 4, 5], value=3)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 165 |
comment = st.text_area("Your Comment:")
|
| 166 |
|
| 167 |
submit_feedback_button = st.form_submit_button("Submit Feedback")
|
|
|
|
| 171 |
st.warning("⚠ Please provide a comment.")
|
| 172 |
else:
|
| 173 |
# Store feedback in PostgreSQL
|
| 174 |
+
if insert_feedback(rating, comment):
|
|
|
|
| 175 |
st.success("Thank you for your feedback!")
|
| 176 |
+
else:
|
| 177 |
+
st.error("Failed to submit feedback.")
|
| 178 |
|
| 179 |
else:
|
| 180 |
st.warning("⚠ Please enter a message.")
|