Update app.py
Browse files
app.py
CHANGED
@@ -1,7 +1,27 @@
|
|
1 |
import gradio as gr
|
2 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
3 |
def greet(name):
|
4 |
-
|
|
|
|
|
5 |
|
6 |
iface = gr.Interface(fn=greet, inputs="text", outputs="text")
|
7 |
iface.launch()
|
|
|
1 |
import gradio as gr
|
2 |
|
3 |
+
import torch
|
4 |
+
from transformers import AutoModelForCausalLM, AutoTokenizer
|
5 |
+
|
6 |
+
model = AutoModelForCausalLM.from_pretrained("cyberagent/open-calm-7b", device_map="auto", torch_dtype=torch.float16)
|
7 |
+
tokenizer = AutoTokenizer.from_pretrained("cyberagent/open-calm-7b")
|
8 |
+
|
9 |
+
def proc( inputs ):
|
10 |
+
with torch.no_grad():
|
11 |
+
tokens = model.generate(
|
12 |
+
**inputs,
|
13 |
+
max_new_tokens=64, # ็ๆใใ้ทใ. 128 ใจใใงใ่ฏใ.
|
14 |
+
do_sample=True,
|
15 |
+
temperature=0.7, # ็ๆใฎใฉใณใใ ๆง. ้ซใใปใฉๆงใ
ใชๅ่ชใๅบใฆใใใ้ข้ฃๆงใฏไธใใ.
|
16 |
+
pad_token_id=tokenizer.pad_token_id,
|
17 |
+
)
|
18 |
+
|
19 |
+
return = tokenizer.decode(tokens[0], skip_special_tokens=True)
|
20 |
+
|
21 |
def greet(name):
|
22 |
+
inputs = tokenizer(name, return_tensors="pt").to(model.device)
|
23 |
+
outputs = proc( inputs )
|
24 |
+
return( outputs )
|
25 |
|
26 |
iface = gr.Interface(fn=greet, inputs="text", outputs="text")
|
27 |
iface.launch()
|