Daemontatox commited on
Commit
e232de0
·
verified ·
1 Parent(s): ffcf7c4

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +108 -45
app.py CHANGED
@@ -195,26 +195,22 @@ def main():
195
  with gr.Row():
196
  with gr.Column():
197
  chat_history = gr.State([])
198
- chatbot = gr.Chatbot(
199
- value=[],
200
- height=750,
201
- show_label=False,
202
- bubble_full_width=False,
203
  elem_classes=["chat-area"],
204
  )
205
 
 
 
 
 
 
 
206
  with gr.Row():
207
- with gr.Column(scale=20):
208
- message = gr.TextArea(
209
- placeholder=PLACEHOLDER,
210
- label="Your message",
211
- lines=3,
212
- show_label=False
213
- )
214
- with gr.Column(scale=4):
215
- with gr.Row():
216
- submit = gr.Button("Send", variant="primary", size="sm")
217
- clear = gr.Button("Clear", size="sm")
218
 
219
  with gr.Accordion("⚙️ Advanced Settings", open=False):
220
  system_prompt = gr.TextArea(
@@ -257,40 +253,107 @@ def main():
257
  value=1.2,
258
  label="Repetition Penalty",
259
  )
260
-
261
- # Set up submit events for both button click and Enter key
262
- submit_events = [submit.click, message.submit]
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
263
 
264
- for event in submit_events:
265
- event(
266
- chat_response,
267
- inputs=[
268
- message,
269
- chat_history,
270
- chatbot,
271
- system_prompt,
272
- temperature,
273
- max_tokens,
274
- top_p,
275
- top_k,
276
- penalty,
277
- ],
278
- outputs=[chat_history, chatbot],
279
- show_progress=True,
280
- ).then(
281
- lambda: "",
282
- outputs=message
283
- )
284
-
285
- # Clear chat functionality
286
  clear.click(
287
- lambda: ([], []),
288
- outputs=[chat_history, chatbot],
289
  show_progress=True,
290
  )
291
-
 
 
 
 
292
  return demo
293
 
294
  if __name__ == "__main__":
295
  demo = main()
296
- demo.launch()
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
195
  with gr.Row():
196
  with gr.Column():
197
  chat_history = gr.State([])
198
+ chat_display = gr.TextArea(
199
+ value="",
200
+ label="Chat History",
201
+ interactive=False,
 
202
  elem_classes=["chat-area"],
203
  )
204
 
205
+ message = gr.TextArea(
206
+ placeholder=PLACEHOLDER,
207
+ label="Your message",
208
+ lines=3
209
+ )
210
+
211
  with gr.Row():
212
+ submit = gr.Button("Send")
213
+ clear = gr.Button("Clear")
 
 
 
 
 
 
 
 
 
214
 
215
  with gr.Accordion("⚙️ Advanced Settings", open=False):
216
  system_prompt = gr.TextArea(
 
253
  value=1.2,
254
  label="Repetition Penalty",
255
  )
256
+
257
+ examples = gr.Examples(
258
+ examples=create_examples(),
259
+ inputs=[message],
260
+ outputs=[chat_history, chat_display],
261
+ fn=process_example,
262
+ cache_examples=False,
263
+ )
264
+
265
+ # Set up event handlers
266
+ submit_click = submit.click(
267
+ chat_response,
268
+ inputs=[
269
+ message,
270
+ chat_history,
271
+ chat_display,
272
+ system_prompt,
273
+ temperature,
274
+ max_tokens,
275
+ top_p,
276
+ top_k,
277
+ penalty,
278
+ ],
279
+ outputs=[chat_history, chat_display],
280
+ show_progress=True,
281
+ )
282
+
283
+ # Bind Enter key to submit
284
+ message.submit(
285
+ chat_response,
286
+ inputs=[
287
+ message,
288
+ chat_history,
289
+ chat_display,
290
+ system_prompt,
291
+ temperature,
292
+ max_tokens,
293
+ top_p,
294
+ top_k,
295
+ penalty,
296
+ ],
297
+ outputs=[chat_history, chat_display],
298
+ show_progress=True,
299
+ )
300
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
301
  clear.click(
302
+ lambda: ([], ""),
303
+ outputs=[chat_history, chat_display],
304
  show_progress=True,
305
  )
306
+
307
+ # Clear input after submission
308
+ submit_click.then(lambda: "", outputs=message)
309
+ message.submit(lambda: "", outputs=message)
310
+
311
  return demo
312
 
313
  if __name__ == "__main__":
314
  demo = main()
315
+ demo.launch()
316
+
317
+
318
+ modify the send function and use the following asa reference :
319
+
320
+
321
+
322
+ with gr.Blocks() as iface:
323
+ gr.Image("Image.jpg", width=750, height=300, show_label=False, show_download_button=False)
324
+ gr.Markdown("# Mawared HR Assistant 3.0.0")
325
+ gr.Markdown('### Instructions')
326
+ gr.Markdown("Ask a question about MawaredHR and get a detailed answer")
327
+
328
+ chatbot = gr.Chatbot(
329
+ height=750,
330
+ show_label=False,
331
+ bubble_full_width=False,
332
+ )
333
+
334
+ with gr.Row():
335
+ with gr.Column(scale=20):
336
+ question_input = gr.Textbox(
337
+ label="Ask a question:",
338
+ placeholder="Type your question here...",
339
+ show_label=False
340
+ )
341
+ with gr.Column(scale=4):
342
+ with gr.Row():
343
+ with gr.Column():
344
+ send_button = gr.Button("Send", variant="primary", size="sm")
345
+ clear_button = gr.Button("Clear Chat", size="sm")
346
+
347
+ # Handle both submit events (Enter key and Send button)
348
+ submit_events = [question_input.submit, send_button.click]
349
+ for submit_event in submit_events:
350
+ submit_event(
351
+ ask_question_gradio,
352
+ inputs=[question_input, chatbot],
353
+ outputs=[question_input, chatbot]
354
+ )
355
+
356
+ clear_button.click(
357
+ clear_chat,
358
+ outputs=[chatbot, question_input]
359
+ )