miaota commited on
Commit
1c95dd5
·
verified ·
1 Parent(s): 7cc4881

Upload 2 files

Browse files
Files changed (2) hide show
  1. app.py +24 -0
  2. requirements.txt +3 -0
app.py ADDED
@@ -0,0 +1,24 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ from transformers import pipeline
3
+
4
+ pipe = pipeline(
5
+ "text-generation",
6
+ model="cmz1024/olmo3-190m-zh-nano",
7
+ model_kwargs={"attn_implementation": "sdpa"},
8
+ ) # 替换你的模型
9
+
10
+
11
+ def predict(message):
12
+ output = pipe(
13
+ message,
14
+ max_new_tokens=256,
15
+ do_sample=True, # 开启采样(默认是贪心解码)
16
+ temperature=0.7, # 温度,越高越随机
17
+ top_k=50, # 只从概率最高的 k 个 token 中采样
18
+ top_p=0.9, # 核采样,累积概率截断
19
+ repetition_penalty=1.2, # 重复惩罚
20
+ )
21
+ return output[0]["generated_text"]
22
+
23
+
24
+ gr.Interface(fn=predict, inputs="text", outputs="text").launch()
requirements.txt ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ transformers
2
+ torch
3
+ accelerate