mery22 commited on
Commit
fc390a9
1 Parent(s): a55ea14

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +28 -55
app.py CHANGED
@@ -41,7 +41,6 @@ Answer in french only
41
 
42
  {context}
43
  Vous devez répondre aux questions en français.
44
-
45
  ### QUESTION:
46
  {question}
47
  [/INST]
@@ -61,7 +60,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,13 +94,6 @@ st.markdown("""
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,52 +101,33 @@ st.markdown("""
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
-
 
41
 
42
  {context}
43
  Vous devez répondre aux questions en français.
 
44
  ### QUESTION:
45
  {question}
46
  [/INST]
 
60
  template=prompt_template,
61
  )
62
 
63
+ # Create LLM chain
64
  llm_chain = LLMChain(llm=mistral_llm, prompt=prompt)
65
 
66
  # Create RetrievalQA chain
 
94
  .centered-text {
95
  text-align: center;
96
  }
 
 
 
 
 
 
 
97
  .centered-orange-text {
98
  text-align: center;
99
  color: darkorange;
 
101
  </style>
102
  """, unsafe_allow_html=True)
103
 
104
+ # Use CSS classes to style the text
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='interaction_form'):
110
+ user_input = st.text_input("You:", key="user_input")
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, key="rating")
121
+
122
+ st.markdown("### Leave a comment:")
123
+ comment = st.text_area("", key="comment")
124
+
125
+ # Feedback submission
126
+ feedback_submit_button = st.form_submit_button("Submit Feedback")
127
+
128
+ if feedback_submit_button:
129
+ if comment.strip():
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.")