mery22 commited on
Commit
7ceafd3
1 Parent(s): f2450be

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +25 -25
app.py CHANGED
@@ -17,15 +17,15 @@ scope = ["https://www.googleapis.com/auth/spreadsheets", "https://www.googleapis
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
- sheet_id = "1Jf1k7Q71ihsxBf-XQYyucamMy14q7IjhUDlU8ZzR_Nc" # Replace with your Sheet ID
21
- sheet = client.open_by_key(sheet_id).sheet1 # Use the sheet ID to open the sheet
22
 
23
- # Function to save feedback to Google Sheets
24
  def save_feedback(user_input, bot_response, rating, comment):
25
  feedback = [user_input, bot_response, rating, comment]
26
  sheet.append_row(feedback)
27
 
28
- # Connect to Hugging Face API
29
  from huggingface_hub import login
30
  login(token=st.secrets["HF_TOKEN"])
31
 
@@ -41,6 +41,7 @@ Answer in french only
41
 
42
  {context}
43
  Vous devez répondre aux questions en français.
 
44
  ### QUESTION:
45
  {question}
46
  [/INST]
@@ -71,10 +72,10 @@ qa = RetrievalQA.from_chain_type(
71
  chain_type_kwargs={"prompt": prompt},
72
  )
73
 
74
- # Streamlit interface setup
75
  st.set_page_config(page_title="Alter-IA Chat", page_icon="🤖")
76
 
77
- # Function to handle user input and display chatbot response
78
  def chatbot_response(user_input):
79
  response = qa.run(user_input)
80
  return response
@@ -104,30 +105,29 @@ st.markdown("""
104
  st.markdown('<h3 class="centered-text">🤖 AlteriaChat 🤖</h3>', unsafe_allow_html=True)
105
  st.markdown('<p class="centered-orange-text">"Votre Réponse à Chaque Défi Méthodologique"</p>', unsafe_allow_html=True)
106
 
107
- # Streamlit form for user interaction
108
  with st.form(key='feedback_form'):
109
  user_input = st.text_input("You:")
110
  submit_button = st.form_submit_button("Ask 📨")
111
 
112
- if submit_button:
113
- if user_input.strip() != "":
114
- bot_response = chatbot_response(user_input)
115
- st.markdown("### Bot:")
116
- st.text_area("", value=bot_response, height=600)
117
 
118
- # Form for feedback
119
- st.markdown("### Rate the response:")
120
- rating = st.slider("Select a rating:", min_value=1, max_value=5, value=1)
121
 
122
- st.markdown("### Leave a comment:")
123
- comment = st.text_area("")
124
 
125
- # Submit feedback
126
- feedback_submit_button = st.form_submit_button("Submit Feedback")
127
 
128
- if feedback_submit_button:
129
- if comment.strip() and rating:
130
- save_feedback(user_input, bot_response, rating, comment)
131
- st.success("Thank you for your feedback!")
132
- else:
133
- st.warning("⚠️ Please provide a comment and a rating.")
 
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 = '1A2B3C4D5E6F7G8H9I0J' # Replace with your Google Sheet ID
21
+ sheet = client.open_by_key(spreadsheet_id).sheet1
22
 
23
+ # Function to save user feedback to Google Sheets
24
  def save_feedback(user_input, bot_response, rating, comment):
25
  feedback = [user_input, bot_response, rating, comment]
26
  sheet.append_row(feedback)
27
 
28
+ # Hugging Face API login
29
  from huggingface_hub import login
30
  login(token=st.secrets["HF_TOKEN"])
31
 
 
41
 
42
  {context}
43
  Vous devez répondre aux questions en français.
44
+
45
  ### QUESTION:
46
  {question}
47
  [/INST]
 
72
  chain_type_kwargs={"prompt": prompt},
73
  )
74
 
75
+ # Streamlit interface with improved aesthetics
76
  st.set_page_config(page_title="Alter-IA Chat", page_icon="🤖")
77
 
78
+ # Define function to handle user input and display chatbot response
79
  def chatbot_response(user_input):
80
  response = qa.run(user_input)
81
  return response
 
105
  st.markdown('<h3 class="centered-text">🤖 AlteriaChat 🤖</h3>', unsafe_allow_html=True)
106
  st.markdown('<p class="centered-orange-text">"Votre Réponse à Chaque Défi Méthodologique"</p>', unsafe_allow_html=True)
107
 
108
+ # Input and button for user interaction
109
  with st.form(key='feedback_form'):
110
  user_input = st.text_input("You:")
111
  submit_button = st.form_submit_button("Ask 📨")
112
 
113
+ if submit_button and user_input.strip() != "":
114
+ bot_response = chatbot_response(user_input)
115
+ st.markdown("### Bot:")
116
+ st.text_area("", value=bot_response, height=600)
 
117
 
118
+ # Feedback form
119
+ st.markdown("### Rate the response:")
120
+ rating = st.slider("Select a rating:", min_value=1, max_value=5, value=1)
121
 
122
+ st.markdown("### Leave a comment:")
123
+ comment = st.text_area("")
124
 
125
+ # Feedback submission
126
+ feedback_submit_button = st.form_submit_button("Submit Feedback")
127
 
128
+ if feedback_submit_button:
129
+ if comment.strip() and rating:
130
+ save_feedback(user_input, bot_response, rating, comment)
131
+ st.success("Thank you for your feedback!")
132
+ else:
133
+ st.warning("⚠️ Please provide a comment and a rating.")