localsavageai commited on
Commit
1bf83d1
·
verified ·
1 Parent(s): 5dba10b

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +47 -10
app.py CHANGED
@@ -131,6 +131,16 @@ def generate_response(user_input: str, vector_store: FAISS) -> Optional[str]:
131
  return "Une erreur s'est produite lors de la génération de la réponse."
132
 
133
 
 
 
 
 
 
 
 
 
 
 
134
  def chatbot(query):
135
  """Main function to run the chatbot"""
136
  try:
@@ -146,7 +156,7 @@ def get_random_questions():
146
  """Get 3 random example questions"""
147
  return random.sample(EXAMPLE_QUESTIONS, 3)
148
 
149
- with gr.Blocks(title="MTC Chatbot") as demo: # Removed the theme=gr.themes.Soft() to use the default light theme
150
  # Header Section
151
  gr.Markdown("""
152
  <div style="text-align: center;">
@@ -155,20 +165,28 @@ with gr.Blocks(title="MTC Chatbot") as demo: # Removed the theme=gr.themes.Soft
155
  </div>
156
  """)
157
 
158
- # Chat Interface
159
  chatbot = gr.Chatbot(
160
  label="Dialogue",
161
  bubble_full_width=False,
162
- )
 
 
163
 
164
- # Input Section
165
  with gr.Row():
166
  msg = gr.Textbox(
167
- scale=7,
168
  placeholder="Écrivez votre question ici...",
169
- container=False
 
 
 
 
 
 
 
170
  )
171
- btn = gr.Button("Envoyer", scale=1)
172
 
173
  # Example Questions
174
  with gr.Row():
@@ -179,7 +197,25 @@ with gr.Blocks(title="MTC Chatbot") as demo: # Removed the theme=gr.themes.Soft
179
  examples_per_page=3
180
  )
181
 
182
- # Chat Functions
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
183
  def respond(message, chat_history):
184
  try:
185
  vs = initialize_vector_store()
@@ -187,8 +223,9 @@ with gr.Blocks(title="MTC Chatbot") as demo: # Removed the theme=gr.themes.Soft
187
  chat_history.append((message, response))
188
  return "", chat_history
189
  except Exception as e:
190
- logging.error(f"Error: {str(e)}")
191
- return "", chat_history + [(message, f"Erreur: {str(e)}")]
 
192
 
193
  # Event Handling
194
  btn.click(
 
131
  return "Une erreur s'est produite lors de la génération de la réponse."
132
 
133
 
134
+ def chatbot(query):
135
+ """Main function to run the chatbot"""
136
+ try:
137
+ vs = initialize_vector_store()
138
+ response = generate_response(query, vs)
139
+ return response or "Aucune réponse générée."
140
+ except Exception as e:
141
+ logging.error(f"Chatbot error: {str(e)}")
142
+ return f"Une erreur s'est produite : {str(e)}"
143
+
144
  def chatbot(query):
145
  """Main function to run the chatbot"""
146
  try:
 
156
  """Get 3 random example questions"""
157
  return random.sample(EXAMPLE_QUESTIONS, 3)
158
 
159
+ with gr.Blocks(title="MTC Chatbot", css=".gradio-container {max-width: 100% !important}") as demo:
160
  # Header Section
161
  gr.Markdown("""
162
  <div style="text-align: center;">
 
165
  </div>
166
  """)
167
 
168
+ # Chat Interface - Full width and fixed height
169
  chatbot = gr.Chatbot(
170
  label="Dialogue",
171
  bubble_full_width=False,
172
+ height=600,
173
+ container=True,
174
+ )
175
 
176
+ # Input Section - Larger elements
177
  with gr.Row():
178
  msg = gr.Textbox(
179
+ scale=14,
180
  placeholder="Écrivez votre question ici...",
181
+ container=False,
182
+ lines=3,
183
+ elem_classes=["large-input"]
184
+ )
185
+ btn = gr.Button(
186
+ "Envoyer",
187
+ scale=2,
188
+ elem_classes=["large-button"]
189
  )
 
190
 
191
  # Example Questions
192
  with gr.Row():
 
197
  examples_per_page=3
198
  )
199
 
200
+ # Custom CSS for styling
201
+ demo.css = """
202
+ .large-input textarea {
203
+ min-height: 120px !important;
204
+ font-size: 16px !important;
205
+ }
206
+ .large-button {
207
+ height: 120px !important;
208
+ font-size: 16px !important;
209
+ }
210
+ .gradio-container {
211
+ max-width: 100% !important;
212
+ }
213
+ .container {
214
+ max-width: 100% !important;
215
+ }
216
+ """
217
+
218
+ # Chat Functions with improved error handling
219
  def respond(message, chat_history):
220
  try:
221
  vs = initialize_vector_store()
 
223
  chat_history.append((message, response))
224
  return "", chat_history
225
  except Exception as e:
226
+ logging.error(f"Error: {str(e)}", exc_info=True)
227
+ error_msg = "Désolé, une erreur technique est survenue. Veuillez réessayer."
228
+ return "", chat_history + [(message, error_msg)]
229
 
230
  # Event Handling
231
  btn.click(