Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -74,20 +74,46 @@ st.set_page_config(page_title="Alter-IA Chat", page_icon="🤖")
|
|
| 74 |
def chatbot_response(user_input):
|
| 75 |
response = qa.run(user_input)
|
| 76 |
return response
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 77 |
|
| 78 |
# Define function to save feedback to CSV
|
| 79 |
def save_feedback(question, response, rating, comment):
|
| 80 |
try:
|
| 81 |
-
filename = '
|
| 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:
|
|
|
|
| 74 |
def chatbot_response(user_input):
|
| 75 |
response = qa.run(user_input)
|
| 76 |
return response
|
| 77 |
+
import os
|
| 78 |
+
import csv
|
| 79 |
+
import streamlit as st
|
| 80 |
+
from huggingface_hub import Repository, HfApi
|
| 81 |
+
|
| 82 |
+
# Initialize the repository
|
| 83 |
+
reposss_id = "mery22/testing" # Replace with your repo ID
|
| 84 |
+
reposss = Repository(local_dir=".", clone_from=reposss_id, token=st.secrets["HF_TOKEN"])
|
| 85 |
|
| 86 |
# Define function to save feedback to CSV
|
| 87 |
def save_feedback(question, response, rating, comment):
|
| 88 |
try:
|
| 89 |
+
filename = 'feedback.csv'
|
| 90 |
file_exists = os.path.isfile(filename)
|
|
|
|
| 91 |
|
| 92 |
+
# Open CSV file and append the new feedback
|
| 93 |
with open(filename, 'a', newline='', encoding='utf-8') as csvfile:
|
| 94 |
fieldnames = ['question', 'response', 'rating', 'comment']
|
| 95 |
writer = csv.DictWriter(csvfile, fieldnames=fieldnames)
|
| 96 |
if not file_exists:
|
| 97 |
writer.writeheader()
|
| 98 |
writer.writerow({'question': question, 'response': response, 'rating': rating, 'comment': comment})
|
| 99 |
+
|
| 100 |
+
# Push the updated file to the Hugging Face repository
|
| 101 |
+
repo.push_to_hub(commit_message="Updated feedback")
|
| 102 |
+
|
| 103 |
+
st.success("Thank you for your feedback! It has been saved.")
|
| 104 |
+
except Exception as e:
|
| 105 |
+
st.error(f"Error saving feedback: {e}")
|
| 106 |
+
st.write(f"Exception: {e}")
|
| 107 |
+
|
| 108 |
+
# Example usage:
|
| 109 |
+
question = "What is the capital of France?"
|
| 110 |
+
response = "The capital of France is Paris."
|
| 111 |
+
rating = 5
|
| 112 |
+
comment = "Good response!"
|
| 113 |
+
|
| 114 |
+
# Save feedback and check the output in Streamlit
|
| 115 |
+
save_feedback(question, response, rating, comment)
|
| 116 |
+
|
| 117 |
|
| 118 |
st.success("Thank you for your feedback! It has been saved.")
|
| 119 |
except Exception as e:
|