mery22 commited on
Commit
492e3f4
1 Parent(s): c815ce5

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +57 -30
app.py CHANGED
@@ -12,12 +12,12 @@ import json
12
  # Load Google service account credentials from Hugging Face secrets
13
  GOOGLE_SERVICE_ACCOUNT_JSON = st.secrets["GOOGLE_SERVICE_ACCOUNT_JSON"]
14
 
15
- # Google Sheets setup
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' # 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
@@ -61,7 +61,7 @@ prompt = PromptTemplate(
61
  template=prompt_template,
62
  )
63
 
64
- # Create LLM chain
65
  llm_chain = LLMChain(llm=mistral_llm, prompt=prompt)
66
 
67
  # Create RetrievalQA chain
@@ -95,6 +95,13 @@ st.markdown("""
95
  .centered-text {
96
  text-align: center;
97
  }
 
 
 
 
 
 
 
98
  .centered-orange-text {
99
  text-align: center;
100
  color: darkorange;
@@ -102,32 +109,52 @@ st.markdown("""
102
  </style>
103
  """, unsafe_allow_html=True)
104
 
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.")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
12
  # Load Google service account credentials from Hugging Face secrets
13
  GOOGLE_SERVICE_ACCOUNT_JSON = st.secrets["GOOGLE_SERVICE_ACCOUNT_JSON"]
14
 
15
+ # Google Sheets API v4 setup
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 = '1A2B3C4D5E6F7G8H9I0J' # Replace with your actual spreadsheet ID
21
  sheet = client.open_by_key(spreadsheet_id).sheet1
22
 
23
  # Function to save user feedback to Google Sheets
 
61
  template=prompt_template,
62
  )
63
 
64
+ # Create llm chain
65
  llm_chain = LLMChain(llm=mistral_llm, prompt=prompt)
66
 
67
  # Create RetrievalQA chain
 
95
  .centered-text {
96
  text-align: center;
97
  }
98
+ </style>
99
+ """, unsafe_allow_html=True)
100
+
101
+ # Utiliser la classe CSS pour centrer et colorer le texte
102
+ st.markdown('<h3 class="centered-text">🤖 AlteriaChat 🤖 </h3>', unsafe_allow_html=True)
103
+ st.markdown("""
104
+ <style>
105
  .centered-orange-text {
106
  text-align: center;
107
  color: darkorange;
 
109
  </style>
110
  """, unsafe_allow_html=True)
111
 
112
+ # Centrer et colorer en orange foncé le texte spécifique
113
+ st.markdown('<p class="centered-orange-text">"Votre Réponse à Chaque Défi Méthodologique "</p>', unsafe_allow_html=True)
114
 
115
  # Input and button for user interaction
116
+ user_input = st.text_input("You:", "")
117
+ submit_button = st.button("Ask 📨")
118
+
119
+ import streamlit as st
120
+ import gspread
121
+ from oauth2client.service_account import ServiceAccountCredentials
122
+ import json
123
+
124
+ # Load Google service account credentials from Hugging Face secrets
125
+ GOOGLE_SERVICE_ACCOUNT_JSON = st.secrets["GOOGLE_SERVICE_ACCOUNT_JSON"]
126
+
127
+ # Google Sheets API v4 setup
128
+ scope = ["https://www.googleapis.com/auth/spreadsheets", "https://www.googleapis.com/auth/drive"]
129
+ service_account_info = json.loads(GOOGLE_SERVICE_ACCOUNT_JSON)
130
+ creds = ServiceAccountCredentials.from_json_keyfile_dict(service_account_info, scope)
131
+ client = gspread.authorize(creds)
132
+ sheet = client.open("users feedback").sheet1 # Replace with your Google Sheet name
133
+
134
+ # Function to save user feedback to Google Sheets
135
+ def save_feedback(user_input, bot_response, rating, comment):
136
+ feedback = [user_input, bot_response, rating, comment]
137
+ sheet.append_row(feedback)
138
+
139
+ # Streamlit app layout
140
+
141
+
142
+ user_input = st.text_input("You:")
143
+ bot_response = "This is a bot response." # Replace this with your chatbot's response logic
144
+
145
+ st.markdown("### Rate the response:")
146
+ rating = st.selectbox("", [1, 2, 3, 4, 5])
147
+
148
+ st.markdown("### Leave a comment:")
149
+ comment = st.text_area("")
150
+
151
+ if st.button("Submit"):
152
+ if user_input.strip() and comment.strip():
153
+ save_feedback(user_input, bot_response, rating, comment)
154
+ st.success("Thank you for your feedback!")
155
+ else:
156
+ st.warning("Please provide both input and comment.")
157
+
158
+ st.markdown("---")
159
+ st.markdown("Collaboration is the key to success. Each question finds its answer, each challenge becomes an opportunity.")
160
+