yasserrmd commited on
Commit
6de18d9
1 Parent(s): 342b9d4

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +5 -21
app.py CHANGED
@@ -26,32 +26,16 @@ def chat(input_text, history=[]):
26
 
27
 
28
  with gr.Blocks() as app:
29
- gr.Markdown("<h1 style='text-align: center;'>دردشة أطلس</h1>")
30
  chatbot = gr.Chatbot(label="المحادثة")
31
  state = gr.State([])
32
 
33
  with gr.Row():
34
- txt = gr.Textbox(show_label=False, placeholder="اكتب رسالتك هنا...").style(container=False)
35
  send_button = gr.Button("إرسال")
36
 
37
- # Define the button click event
38
- def user_input(input_text, history):
39
- return "", history + [[input_text, None]]
40
-
41
- def bot_response(history):
42
- user_message = history[-1][0]
43
- inputs = tokenizer(user_message, return_tensors="pt").to(model.device)
44
- outputs = model.generate(**inputs, max_new_tokens=150)
45
- response = tokenizer.decode(outputs[0], skip_special_tokens=True)
46
- history[-1][1] = response
47
- return history
48
-
49
- # Link functions to button clicks
50
- txt.submit(user_input, [txt, state], [txt, state]).then(
51
- bot_response, state, chatbot
52
- )
53
- send_button.click(user_input, [txt, state], [txt, state]).then(
54
- bot_response, state, chatbot
55
- )
56
 
57
  app.launch()
 
26
 
27
 
28
  with gr.Blocks() as app:
29
+ gr.Markdown("<h1 style='text-align: center;'>دردشة أطلس-شات 27B</h1>")
30
  chatbot = gr.Chatbot(label="المحادثة")
31
  state = gr.State([])
32
 
33
  with gr.Row():
34
+ txt = gr.Textbox(show_label=False, placeholder="اكتب رسالتك هنا...")
35
  send_button = gr.Button("إرسال")
36
 
37
+ # Link the chat function to both text submission and button click
38
+ txt.submit(chat, [txt, state], [chatbot, state])
39
+ send_button.click(chat, [txt, state], [chatbot, state])
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
40
 
41
  app.launch()