frankhuangg commited on
Commit
0abb7ea
·
verified ·
1 Parent(s): 0491ee6

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +26 -0
app.py ADDED
@@ -0,0 +1,26 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ from transformers import AutoModelForCausalLM, AutoTokenizer
3
+ import torch
4
+
5
+ # 加载模型和分词器
6
+ model_name = "taide/Llama3-TAIDE-LX-8B-Chat-Alpha1"
7
+ tokenizer = AutoTokenizer.from_pretrained(model_name)
8
+ model = AutoModelForCausalLM.from_pretrained(model_name, torch_dtype=torch.float16, device_map="auto")
9
+
10
+ # 定义推理函数
11
+ def generate_text(prompt):
12
+ inputs = tokenizer(prompt, return_tensors="pt").to("cuda")
13
+ outputs = model.generate(**inputs)
14
+ return tokenizer.decode(outputs[0], skip_special_tokens=True)
15
+
16
+ # 创建 Gradio 界面
17
+ interface = gr.Interface(
18
+ fn=generate_text,
19
+ inputs="text",
20
+ outputs="text",
21
+ title="Llama3 Chatbot",
22
+ description="与 Llama3-TAIDE-LX-8B-Chat-Alpha1 交谈"
23
+ )
24
+
25
+ # 启动 Gradio 应用
26
+ interface.launch()