eslamirad commited on
Commit
eeca8d3
·
verified ·
1 Parent(s): c84ac4d

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +27 -10
app.py CHANGED
@@ -1,14 +1,31 @@
1
  import gradio as gr
2
- from huggingface_hub import InferenceClient
3
- # Use a pipeline as a high-level helper
4
- from transformers import pipeline
5
 
6
- messages = [
7
- {"role": "user", "content": "Who are you?"},
8
- ]
9
- pipe = pipeline("text-generation", model="Qwen/Qwen2.5-14B-Instruct-1M")
10
- pipe(messages)
11
 
 
 
 
 
 
 
 
12
 
13
- if __name__ == "__main__":
14
- demo.launch()
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  import gradio as gr
2
+ from transformers import AutoModelForCausalLM, AutoTokenizer
3
+ import torch
 
4
 
5
+ MODEL_NAME = "Qwen/Qwen2.5-14B-Instruct-1M"
 
 
 
 
6
 
7
+ # بارگذاری مدل و توکنایزر
8
+ tokenizer = AutoTokenizer.from_pretrained(MODEL_NAME)
9
+ model = AutoModelForCausalLM.from_pretrained(
10
+ MODEL_NAME,
11
+ torch_dtype=torch.float16,
12
+ device_map="auto"
13
+ )
14
 
15
+ # تابع تولید متن
16
+ def chat_with_qwen(prompt):
17
+ inputs = tokenizer(prompt, return_tensors="pt").to("cuda")
18
+ output = model.generate(**inputs, max_new_tokens=200)
19
+ response = tokenizer.decode(output[0], skip_special_tokens=True)
20
+ return response
21
+
22
+ # ایجاد رابط کاربری با Gradio
23
+ iface = gr.Interface(
24
+ fn=chat_with_qwen,
25
+ inputs=gr.Textbox(lines=2, placeholder="سوال خود را اینجا بنویسی"),
26
+ outputs="text",
27
+ title="Qwen 2.5 14B Chatbot",
28
+ description="یک چت‌بات مبتنی بر مدل Qwen/Qwen2.5-14B-Instruct-1M",
29
+ )
30
+
31
+ iface.launch()