yasserrmd commited on
Commit
9ec6197
1 Parent(s): a39566b

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +30 -22
app.py CHANGED
@@ -3,7 +3,7 @@ from transformers import AutoModelForCausalLM, AutoTokenizer
3
  import torch
4
  import spaces
5
 
6
- model_name = "MBZUAI-Paris/Atlas-Chat-27B"
7
  dtype = torch.bfloat16
8
  model = AutoModelForCausalLM.from_pretrained(
9
  model_name,
@@ -25,25 +25,33 @@ def chat(input_text, history=[]):
25
  return history, history
26
 
27
 
28
- iface = gr.Interface(
29
- fn=chat,
30
- inputs=[
31
- gr.Textbox(label="أدخل رسالتك هنا"),
32
- gr.State()
33
- ],
34
- outputs=[
35
- gr.Chatbot(label="المحادثة"),
36
- gr.State()
37
- ],
38
- live=True,
39
- title="دردشة أطلس",
40
- description="تطبيق دردشة يعمل بنموذج أطلس-شات لتوفير تفاعل ذكي وسلس",
41
- theme="huggingface",
42
- examples=[
43
- ["مرحباً! كيف يمكنني مساعدتك اليوم؟"],
44
- ["ما هي أخبار التكنولوجيا الحديثة؟"]
45
- ]
46
- )
 
 
 
 
 
 
 
 
 
47
 
48
- # Launch the application
49
- iface.launch()
 
3
  import torch
4
  import spaces
5
 
6
+ model_name = "MBZUAI-Paris/Atlas-Chat-9B"
7
  dtype = torch.bfloat16
8
  model = AutoModelForCausalLM.from_pretrained(
9
  model_name,
 
25
  return history, 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()