vortexa64 commited on
Commit
e636198
·
verified ·
1 Parent(s): 0a9d15e

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +31 -0
app.py ADDED
@@ -0,0 +1,31 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import torch
2
+ from transformers import AutoTokenizer, AutoModelForCausalLM
3
+ import gradio as gr
4
+
5
+ model_id = "Qwen/Qwen2.5-7B-Instruct-GPTQ"
6
+
7
+ tokenizer = AutoTokenizer.from_pretrained(model_id, trust_remote_code=True)
8
+ model = AutoModelForCausalLM.from_pretrained(
9
+ model_id,
10
+ device_map="auto",
11
+ trust_remote_code=True
12
+ )
13
+
14
+ def chat_with_qwen(prompt):
15
+ inputs = tokenizer(prompt, return_tensors="pt").to(model.device)
16
+ outputs = model.generate(
17
+ **inputs,
18
+ max_new_tokens=512,
19
+ do_sample=True,
20
+ temperature=0.7,
21
+ top_p=0.9
22
+ )
23
+ return tokenizer.decode(outputs[0], skip_special_tokens=True)
24
+
25
+ gr.Interface(
26
+ fn=chat_with_qwen,
27
+ inputs=gr.Textbox(lines=4, placeholder="Tulis pertanyaanmu di sini..."),
28
+ outputs="text",
29
+ title="Qwen 2.5 7B INT4 Chatbot",
30
+ description="Ngobrol yuk sama Qwen 2.5 7B versi INT4~ 🧠✨"
31
+ ).launch()