Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -80,15 +80,36 @@ def save_feedback(question, response, rating, comment):
|
|
80 |
try:
|
81 |
filename = '/tmp/feedback.csv' # Use /tmp directory for temporary storage in Spaces
|
82 |
file_exists = os.path.isfile(filename)
|
|
|
|
|
83 |
with open(filename, 'a', newline='', encoding='utf-8') as csvfile:
|
84 |
fieldnames = ['question', 'response', 'rating', 'comment']
|
85 |
writer = csv.DictWriter(csvfile, fieldnames=fieldnames)
|
86 |
if not file_exists:
|
87 |
writer.writeheader()
|
88 |
writer.writerow({'question': question, 'response': response, 'rating': rating, 'comment': comment})
|
|
|
89 |
st.success("Thank you for your feedback! It has been saved.")
|
90 |
except Exception as e:
|
91 |
st.error(f"Error saving feedback: {e}")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
92 |
|
93 |
# Use session state to store user input, bot response, rating, and comment
|
94 |
if 'user_input' not in st.session_state:
|
|
|
80 |
try:
|
81 |
filename = '/tmp/feedback.csv' # Use /tmp directory for temporary storage in Spaces
|
82 |
file_exists = os.path.isfile(filename)
|
83 |
+
st.write(f"Saving feedback to: {filename}") # Debugging: Print the file path
|
84 |
+
|
85 |
with open(filename, 'a', newline='', encoding='utf-8') as csvfile:
|
86 |
fieldnames = ['question', 'response', 'rating', 'comment']
|
87 |
writer = csv.DictWriter(csvfile, fieldnames=fieldnames)
|
88 |
if not file_exists:
|
89 |
writer.writeheader()
|
90 |
writer.writerow({'question': question, 'response': response, 'rating': rating, 'comment': comment})
|
91 |
+
|
92 |
st.success("Thank you for your feedback! It has been saved.")
|
93 |
except Exception as e:
|
94 |
st.error(f"Error saving feedback: {e}")
|
95 |
+
st.write(f"Exception: {e}") # Debugging: Print any exceptions
|
96 |
+
|
97 |
+
# Example usage:
|
98 |
+
question = "What is the capital of France?"
|
99 |
+
response = "The capital of France is Paris."
|
100 |
+
rating = 5
|
101 |
+
comment = "Good response!"
|
102 |
+
|
103 |
+
# Save feedback and check the output in Streamlit
|
104 |
+
save_feedback(question, response, rating, comment)
|
105 |
+
|
106 |
+
# Optionally, display the file content to confirm it was written correctly
|
107 |
+
if st.button("View Feedback File"):
|
108 |
+
try:
|
109 |
+
with open('/tmp/feedback.csv', 'r', encoding='utf-8') as csvfile:
|
110 |
+
st.text(csvfile.read())
|
111 |
+
except FileNotFoundError:
|
112 |
+
st.error("Feedback file not found.")
|
113 |
|
114 |
# Use session state to store user input, bot response, rating, and comment
|
115 |
if 'user_input' not in st.session_state:
|