Spaces:
Sleeping
Sleeping
Commit
•
1df04ca
1
Parent(s):
c334cb2
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,37 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
from transformers import AutoModelForCausalLM, AutoTokenizer
|
3 |
+
|
4 |
+
TOKENIZER_REPO = "MediaTek-Research/Breeze-7B-Instruct-v1_0"
|
5 |
+
tokenizer = AutoTokenizer.from_pretrained(TOKENIZER_REPO)
|
6 |
+
model = AutoModelForCausalLM.from_pretrained(
|
7 |
+
TOKENIZER_REPO,
|
8 |
+
device_map="auto",
|
9 |
+
torch_dtype=torch.bfloat16,
|
10 |
+
)
|
11 |
+
|
12 |
+
|
13 |
+
|
14 |
+
def generate(text):
|
15 |
+
chat_data = []
|
16 |
+
text = text.strip()
|
17 |
+
if text:
|
18 |
+
chat_data.append({"role": "system", "content": text})
|
19 |
+
outputs = model.generate(tokenizer.apply_chat_template(chat, return_tensors="pt"),
|
20 |
+
max_new_tokens=128,
|
21 |
+
top_p=0.01,
|
22 |
+
top_k=85,
|
23 |
+
repetition_penalty=1.1,
|
24 |
+
temperature=0.01)
|
25 |
+
|
26 |
+
print(tokenizer.decode(outputs[0]))
|
27 |
+
return tokenizer.decode(outputs[0])
|
28 |
+
|
29 |
+
gradio_app = gr.Interface(
|
30 |
+
generate,
|
31 |
+
inputs=gr.Text(),
|
32 |
+
outputs=gr.Text(),
|
33 |
+
title="test",
|
34 |
+
)
|
35 |
+
|
36 |
+
if __name__ == "__main__":
|
37 |
+
gradio_app.launch()
|