yasserrmd commited on
Commit
fccd3f3
ยท
verified ยท
1 Parent(s): b54c4c2

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +48 -0
app.py ADDED
@@ -0,0 +1,48 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ from transformers import AutoModelForCausalLM, AutoTokenizer
3
+ import torch
4
+ import spaces
5
+
6
+ model_name = "MBZUAI-Paris/Atlas-Chat-27B"
7
+ model = AutoModelForCausalLM.from_pretrained(
8
+ model_name,
9
+ load_in_4bit=True,
10
+ device_map="auto"
11
+ )
12
+ tokenizer = AutoTokenizer.from_pretrained(model_name)
13
+
14
+
15
+ @spaces.GPU
16
+ def chat(input_text, history=[]):
17
+ # Tokenize the input and generate response
18
+ inputs = tokenizer(input_text, return_tensors="pt").to(model.device)
19
+ outputs = model.generate(**inputs, max_new_tokens=150)
20
+ response = tokenizer.decode(outputs[0], skip_special_tokens=True)
21
+
22
+ # Update the conversation history
23
+ history.append((input_text, response))
24
+ return history, history
25
+
26
+
27
+ iface = gr.Interface(
28
+ fn=chat,
29
+ inputs=[
30
+ gr.inputs.Textbox(label="ุฃุฏุฎู„ ุฑุณุงู„ุชูƒ ู‡ู†ุง"),
31
+ "state"
32
+ ],
33
+ outputs=[
34
+ gr.outputs.Chatbot(label="ุงู„ู…ุญุงุฏุซุฉ"),
35
+ "state"
36
+ ],
37
+ live=True,
38
+ title="ุฏุฑุฏุดุฉ ุฃุทู„ุณ",
39
+ description="ุชุทุจูŠู‚ ุฏุฑุฏุดุฉ ูŠุนู…ู„ ุจู†ู…ูˆุฐุฌ ุฃุทู„ุณ-ุดุงุช ู„ุชูˆููŠุฑ ุชูุงุนู„ ุฐูƒูŠ ูˆุณู„ุณ",
40
+ theme="huggingface",
41
+ examples=[
42
+ ["ู…ุฑุญุจุงู‹! ูƒูŠู ูŠู…ูƒู†ู†ูŠ ู…ุณุงุนุฏุชูƒ ุงู„ูŠูˆู…ุŸ"],
43
+ ["ู…ุง ู‡ูŠ ุฃุฎุจุงุฑ ุงู„ุชูƒู†ูˆู„ูˆุฌูŠุง ุงู„ุญุฏูŠุซุฉุŸ"]
44
+ ]
45
+ )
46
+
47
+ # Launch the application
48
+ iface.launch()