Spaces:
Runtime error
Runtime error
updated with 8 bit version
Browse files
app.py
CHANGED
@@ -1,25 +1,34 @@
|
|
1 |
import gradio as gr
|
|
|
2 |
|
3 |
-
|
4 |
-
|
5 |
|
6 |
-
|
7 |
-
|
|
|
|
|
|
|
8 |
|
9 |
def text_generation(input_text):
|
10 |
if input_text == "":
|
11 |
return ""
|
12 |
-
|
|
|
|
|
13 |
|
14 |
with gr.Blocks() as demo:
|
15 |
gr.Markdown(
|
16 |
"""
|
17 |
-
# ηΎε·-7B 樑εδ½ιͺ
|
18 |
θΎε
₯ζζ¬δ»₯ζ₯ηηζη»ζγ
|
|
|
|
|
|
|
19 |
""")
|
20 |
-
inp = gr.Textbox(label="θΎε
₯
|
21 |
-
submit = gr.Button("
|
22 |
-
out = gr.Textbox(label="
|
23 |
submit.click(text_generation, inp, out)
|
24 |
|
25 |
gr.Markdown("## Text Examples")
|
|
|
1 |
import gradio as gr
|
2 |
+
from transformers import AutoModelForCausalLM, AutoTokenizer
|
3 |
|
4 |
+
tokenizer = AutoTokenizer.from_pretrained("baichuan-inc/baichuan-7B", trust_remote_code=True)
|
5 |
+
model = AutoModelForCausalLM.from_pretrained("baichuan-inc/baichuan-7B", trust_remote_code=True, device_map="auto", load_in_8bit=True)
|
6 |
|
7 |
+
#from transformers import
|
8 |
+
#from modelscope.pipelines import pipeline
|
9 |
+
#from modelscope.utils.constant import Tasks
|
10 |
+
#text_generation_zh = pipeline(task=Tasks.text_generation, model='baichuan-inc/baichuan-7B',model_revision='v1.0.2')
|
11 |
+
#text_generation_zh._model_prepare = True
|
12 |
|
13 |
def text_generation(input_text):
|
14 |
if input_text == "":
|
15 |
return ""
|
16 |
+
inputs = tokenizer(input_text, return_tensors='pt').to('cuda:0') #"run->walk\nwrite->"
|
17 |
+
pred = model.generate(**inputs, max_new_tokens=64, repetition_penalty=1.1)
|
18 |
+
return tokenizer.decode(pred.cpu()[0], skip_special_tokens=True) #text_generation_zh(input_text)['text']
|
19 |
|
20 |
with gr.Blocks() as demo:
|
21 |
gr.Markdown(
|
22 |
"""
|
23 |
+
# [Chinese] ηΎε·-7B 樑εδ½ιͺ
|
24 |
θΎε
₯ζζ¬δ»₯ζ₯ηηζη»ζγ
|
25 |
+
|
26 |
+
# [English] Baichuan-7B model experience
|
27 |
+
Enter text to see build results.
|
28 |
""")
|
29 |
+
inp = gr.Textbox(label="θΎε
₯Prompt / Input Prompt")
|
30 |
+
submit = gr.Button("ζδΊ€/Submit")
|
31 |
+
out = gr.Textbox(label="η»εη»ζ/Generated Text")
|
32 |
submit.click(text_generation, inp, out)
|
33 |
|
34 |
gr.Markdown("## Text Examples")
|