Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -9,23 +9,25 @@ import gspread
|
|
| 9 |
from oauth2client.service_account import ServiceAccountCredentials
|
| 10 |
import json
|
| 11 |
|
| 12 |
-
|
| 13 |
-
from oauth2client.service_account import ServiceAccountCredentials
|
| 14 |
-
import json
|
| 15 |
-
|
| 16 |
-
# Load Google service account credentials from Hugging Face secrets
|
| 17 |
GOOGLE_SERVICE_ACCOUNT_JSON = st.secrets["GOOGLE_SERVICE_ACCOUNT_JSON"]
|
| 18 |
|
| 19 |
-
# Google Sheets
|
| 20 |
scope = ["https://www.googleapis.com/auth/spreadsheets", "https://www.googleapis.com/auth/drive"]
|
| 21 |
service_account_info = json.loads(GOOGLE_SERVICE_ACCOUNT_JSON)
|
| 22 |
creds = ServiceAccountCredentials.from_json_keyfile_dict(service_account_info, scope)
|
| 23 |
client = gspread.authorize(creds)
|
| 24 |
-
|
|
|
|
|
|
|
| 25 |
# Fonction pour enregistrer les retours utilisateur dans Google Sheets
|
| 26 |
def save_feedback(user_input, bot_response, rating, comment):
|
| 27 |
-
|
| 28 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 29 |
|
| 30 |
# Connexion API Hugging Face
|
| 31 |
from huggingface_hub import login
|
|
@@ -43,7 +45,6 @@ Answer in french only
|
|
| 43 |
|
| 44 |
{context}
|
| 45 |
Vous devez répondre aux questions en français.
|
| 46 |
-
|
| 47 |
### QUESTION:
|
| 48 |
{question}
|
| 49 |
[/INST]
|
|
@@ -130,7 +131,6 @@ with st.form(key='feedback_form'):
|
|
| 130 |
if st.form_submit_button("Submit Feedback"):
|
| 131 |
if comment.strip() and rating:
|
| 132 |
save_feedback(user_input, bot_response, rating, comment)
|
| 133 |
-
st.success("Thank you for your feedback!")
|
| 134 |
else:
|
| 135 |
st.warning("⚠️ Please provide a comment and a rating.")
|
| 136 |
|
|
|
|
| 9 |
from oauth2client.service_account import ServiceAccountCredentials
|
| 10 |
import json
|
| 11 |
|
| 12 |
+
# Charger les informations d'identification du compte de service Google à partir des secrets Hugging Face
|
|
|
|
|
|
|
|
|
|
|
|
|
| 13 |
GOOGLE_SERVICE_ACCOUNT_JSON = st.secrets["GOOGLE_SERVICE_ACCOUNT_JSON"]
|
| 14 |
|
| 15 |
+
# Configuration de Google Sheets
|
| 16 |
scope = ["https://www.googleapis.com/auth/spreadsheets", "https://www.googleapis.com/auth/drive"]
|
| 17 |
service_account_info = json.loads(GOOGLE_SERVICE_ACCOUNT_JSON)
|
| 18 |
creds = ServiceAccountCredentials.from_json_keyfile_dict(service_account_info, scope)
|
| 19 |
client = gspread.authorize(creds)
|
| 20 |
+
spreadsheet_id = '1Jf1k7Q71ihsxBf-XQYyucamMy14q7IjhUDlU8ZzR_Nc' # Remplacez par votre ID de feuille Google
|
| 21 |
+
sheet = client.open_by_key(spreadsheet_id).sheet1
|
| 22 |
+
|
| 23 |
# Fonction pour enregistrer les retours utilisateur dans Google Sheets
|
| 24 |
def save_feedback(user_input, bot_response, rating, comment):
|
| 25 |
+
try:
|
| 26 |
+
feedback = [user_input, bot_response, rating, comment]
|
| 27 |
+
sheet.append_row(feedback)
|
| 28 |
+
st.success("Merci pour votre retour!")
|
| 29 |
+
except Exception as e:
|
| 30 |
+
st.error(f"Erreur lors de l'enregistrement des retours : {e}")
|
| 31 |
|
| 32 |
# Connexion API Hugging Face
|
| 33 |
from huggingface_hub import login
|
|
|
|
| 45 |
|
| 46 |
{context}
|
| 47 |
Vous devez répondre aux questions en français.
|
|
|
|
| 48 |
### QUESTION:
|
| 49 |
{question}
|
| 50 |
[/INST]
|
|
|
|
| 131 |
if st.form_submit_button("Submit Feedback"):
|
| 132 |
if comment.strip() and rating:
|
| 133 |
save_feedback(user_input, bot_response, rating, comment)
|
|
|
|
| 134 |
else:
|
| 135 |
st.warning("⚠️ Please provide a comment and a rating.")
|
| 136 |
|