Samuel-DD07 commited on
Commit
b8c30e3
·
1 Parent(s): 8708baa

Mise à jour de l'interface de chat et des suggestions

Browse files
Files changed (1) hide show
  1. app.py +33 -31
app.py CHANGED
@@ -243,31 +243,40 @@ import gradio as gr
243
 
244
  theme = gr.themes.Base(primary_hue="slate")
245
 
246
- suggestion = ["What are the latest advancements in cancer research ?","What is the impact of diet on heart disease according to recent studies ?","What are the usual causes of lung pain ?"]
 
 
 
 
247
 
248
- def respond(message,chat_history):
249
  response = generate_text(message)
250
- chat_history.append((message, response))
251
- return "bot", chat_history
 
252
 
253
-
254
- def suggestion1():
255
  response = generate_text(suggestion[0])
256
- return [suggestion_text_1,response]
257
- """
258
- def suggestion2():
259
- response = generate_text(suggestion_text_2)
260
- return [["user", suggestion_text_2], ["bot", response]]
261
-
262
- def suggestion3():
263
- response = generate_text(suggestion_text_3)
264
- return [["user", suggestion_text_3], ["bot", response]]
265
- """
 
 
 
 
 
266
 
267
  user_profile_image = "https://github.com/LucasAguetai/ALOQAS/blob/main/Ressources/ALOQAS%20logo.png?raw=true"
268
- bot_profile_image = "https://github.com/LucasAguetai/ALOQAS/blob/main/Ressources/ALOQAS%20logo.png?raw=true"
269
 
270
- with gr.Blocks(theme=theme, css=css) as demo:
271
  gr.Markdown("""
272
  <div id='header'>
273
  <h1 id='main-title'>ALOQAS</h1>
@@ -276,26 +285,19 @@ with gr.Blocks(theme=theme, css=css) as demo:
276
  </div>
277
  """)
278
  with gr.Column(elem_id="chat-interface"):
279
- chat = gr.Chatbot(elem_id="chat-messages", show_label=False,avatar_images=[user_profile_image,bot_profile_image])
280
  with gr.Row(elem_id="suggestions"):
281
  sugg1 = gr.Button(suggestion[0], elem_classes="suggestion-btn").click(
282
- suggestion1, outputs=chat
283
  )
284
  sugg2 = gr.Button(suggestion[1], elem_classes="suggestion-btn").click(
285
- suggestion1, outputs=chat
286
  )
287
  sugg3 = gr.Button(suggestion[2], elem_classes="suggestion-btn").click(
288
- suggestion1, outputs=chat
289
  )
290
  with gr.Row(elem_id="input-area"):
291
  text_input = gr.Textbox(placeholder="Write to ALOQAS...", show_label=False)
292
- #send_button = gr.Button("Send", elem_classes="send")
293
- #send_button.click(
294
- # fn=respond,
295
- # inputs=text_input,
296
- # outputs=chat
297
- #)
298
- text_input.submit(respond, [text_input, chat], [text_input, chat])
299
-
300
- demo.launch(share=False)
301
 
 
 
243
 
244
  theme = gr.themes.Base(primary_hue="slate")
245
 
246
+ suggestion = [
247
+ "What are the latest advancements in cancer research ?",
248
+ "What is the impact of diet on heart disease according to recent studies ?",
249
+ "What are the usual causes of lung pain ?"
250
+ ]
251
 
252
+ def respond(message, chat_history):
253
  response = generate_text(message)
254
+ chat_history.append((None, message))
255
+ chat_history.append((response, None))
256
+ return chat_history
257
 
258
+ def suggestion1(chat_history):
 
259
  response = generate_text(suggestion[0])
260
+ chat_history.append((None, suggestion[0]))
261
+ chat_history.append((response, None))
262
+ return chat_history
263
+
264
+ def suggestion2(chat_history):
265
+ response = generate_text(suggestion[1])
266
+ chat_history.append((None, suggestion[1]))
267
+ chat_history.append((response, None))
268
+ return chat_history
269
+
270
+ def suggestion3(chat_history):
271
+ response = generate_text(suggestion[2])
272
+ chat_history.append((None, suggestion[2]))
273
+ chat_history.append((response, None))
274
+ return chat_history
275
 
276
  user_profile_image = "https://github.com/LucasAguetai/ALOQAS/blob/main/Ressources/ALOQAS%20logo.png?raw=true"
277
+ bot_profile_image = "https://github.com/LucasAguetai/ALOQAS/blob/main/Ressources/pp%20discord%20copie.png?raw=true"
278
 
279
+ with gr.Blocks(theme=theme, css=css) as demo: # Suppression de 'css=css' si 'css' n'est pas défini
280
  gr.Markdown("""
281
  <div id='header'>
282
  <h1 id='main-title'>ALOQAS</h1>
 
285
  </div>
286
  """)
287
  with gr.Column(elem_id="chat-interface"):
288
+ chat = gr.Chatbot(elem_id="chat-messages", show_label=False, avatar_images=[user_profile_image, bot_profile_image])
289
  with gr.Row(elem_id="suggestions"):
290
  sugg1 = gr.Button(suggestion[0], elem_classes="suggestion-btn").click(
291
+ suggestion1, inputs=[chat], outputs=chat
292
  )
293
  sugg2 = gr.Button(suggestion[1], elem_classes="suggestion-btn").click(
294
+ suggestion2, inputs=[chat], outputs=chat
295
  )
296
  sugg3 = gr.Button(suggestion[2], elem_classes="suggestion-btn").click(
297
+ suggestion3, inputs=[chat], outputs=chat
298
  )
299
  with gr.Row(elem_id="input-area"):
300
  text_input = gr.Textbox(placeholder="Write to ALOQAS...", show_label=False)
301
+ text_input.submit(respond, inputs=[text_input, chat], outputs=chat)
 
 
 
 
 
 
 
 
302
 
303
+ demo.launch(share=False)