localsavageai commited on
Commit
5faaab3
·
verified ·
1 Parent(s): 046ab5f

Upload app.py

Browse files
Files changed (1) hide show
  1. app.py +19 -19
app.py CHANGED
@@ -133,6 +133,17 @@ def generate_response(user_input: str, vector_store: FAISS) -> Optional[str]:
133
  return "Une erreur s'est produite lors de la génération de la réponse."
134
 
135
 
 
 
 
 
 
 
 
 
 
 
 
136
  def get_random_questions():
137
  """Get 3 random example questions"""
138
  return random.sample(EXAMPLE_QUESTIONS, 3)
@@ -147,10 +158,10 @@ with gr.Blocks(title="MTC Chatbot", theme=gr.themes.Soft()) as demo:
147
  """)
148
 
149
  # Chat Interface
150
- chatbot_ui = gr.Chatbot(
151
  label="Dialogue",
152
- type="chatbot"
153
- )
154
 
155
  # Input Section
156
  with gr.Row():
@@ -170,18 +181,6 @@ with gr.Blocks(title="MTC Chatbot", theme=gr.themes.Soft()) as demo:
170
  examples_per_page=3
171
  )
172
 
173
- # Hidden API Endpoint
174
- with gr.Row(visible=False):
175
- api_input = gr.Textbox()
176
- api_output = gr.Textbox()
177
- api_btn = gr.Button()
178
- api_btn.click(
179
- fn=api_respond,
180
- inputs=api_input,
181
- outputs=api_output,
182
- api_name="/respond"
183
- )
184
-
185
  # Chat Functions
186
  def respond(message, chat_history):
187
  try:
@@ -196,14 +195,15 @@ with gr.Blocks(title="MTC Chatbot", theme=gr.themes.Soft()) as demo:
196
  # Event Handling
197
  btn.click(
198
  respond,
199
- [msg, chatbot_ui],
200
- [msg, chatbot_ui]
201
  )
202
  msg.submit(
203
  respond,
204
- [msg, chatbot_ui],
205
- [msg, chatbot_ui]
206
  )
207
 
208
  if __name__ == "__main__":
209
  demo.launch()
 
 
133
  return "Une erreur s'est produite lors de la génération de la réponse."
134
 
135
 
136
+ def chatbot(query):
137
+ """Main function to run the chatbot"""
138
+ try:
139
+ vs = initialize_vector_store()
140
+ response = generate_response(query, vs)
141
+ return response or "Aucune réponse générée."
142
+ except Exception as e:
143
+ logging.error(f"Chatbot error: {str(e)}")
144
+ return f"Une erreur s'est produite : {str(e)}"
145
+
146
+ # Gradio Interface Simplification
147
  def get_random_questions():
148
  """Get 3 random example questions"""
149
  return random.sample(EXAMPLE_QUESTIONS, 3)
 
158
  """)
159
 
160
  # Chat Interface
161
+ chatbot = gr.Chatbot(
162
  label="Dialogue",
163
+ bubble_full_width=False,
164
+ )
165
 
166
  # Input Section
167
  with gr.Row():
 
181
  examples_per_page=3
182
  )
183
 
 
 
 
 
 
 
 
 
 
 
 
 
184
  # Chat Functions
185
  def respond(message, chat_history):
186
  try:
 
195
  # Event Handling
196
  btn.click(
197
  respond,
198
+ [msg, chatbot],
199
+ [msg, chatbot]
200
  )
201
  msg.submit(
202
  respond,
203
+ [msg, chatbot],
204
+ [msg, chatbot]
205
  )
206
 
207
  if __name__ == "__main__":
208
  demo.launch()
209
+