Spaces:
Sleeping
Sleeping
Update app.py
Browse files
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-
|
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 |
-
|
29 |
-
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
-
|
34 |
-
|
35 |
-
gr.
|
36 |
-
|
37 |
-
|
38 |
-
|
39 |
-
|
40 |
-
|
41 |
-
|
42 |
-
|
43 |
-
|
44 |
-
|
45 |
-
|
46 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
47 |
|
48 |
-
|
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()
|
|