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

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +10 -37
app.py CHANGED
@@ -156,7 +156,7 @@ def get_random_questions():
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,28 +165,20 @@ with gr.Blocks(title="MTC Chatbot", css=".gradio-container {max-width: 100% !imp
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,25 +189,7 @@ with gr.Blocks(title="MTC Chatbot", css=".gradio-container {max-width: 100% !imp
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,9 +197,8 @@ with gr.Blocks(title="MTC Chatbot", css=".gradio-container {max-width: 100% !imp
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(
 
156
  """Get 3 random example questions"""
157
  return random.sample(EXAMPLE_QUESTIONS, 3)
158
 
159
+ with gr.Blocks(title="MTC Chatbot") as demo: # Removed the theme=gr.themes.Soft() to use the default light theme
160
  # Header Section
161
  gr.Markdown("""
162
  <div style="text-align: center;">
 
165
  </div>
166
  """)
167
 
168
+ # Chat Interface
169
  chatbot = gr.Chatbot(
170
  label="Dialogue",
171
  bubble_full_width=False,
172
+ )
 
 
173
 
174
+ # Input Section
175
  with gr.Row():
176
  msg = gr.Textbox(
177
+ scale=7,
178
  placeholder="Écrivez votre question ici...",
179
+ container=False
 
 
 
 
 
 
 
180
  )
181
+ btn = gr.Button("Envoyer", scale=1)
182
 
183
  # Example Questions
184
  with gr.Row():
 
189
  examples_per_page=3
190
  )
191
 
192
+ # Chat Functions
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
193
  def respond(message, chat_history):
194
  try:
195
  vs = initialize_vector_store()
 
197
  chat_history.append((message, response))
198
  return "", chat_history
199
  except Exception as e:
200
+ logging.error(f"Error: {str(e)}")
201
+ return "", chat_history + [(message, f"Erreur: {str(e)}")]
 
202
 
203
  # Event Handling
204
  btn.click(