Spaces:
Runtime error
Runtime error
create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,35 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
|
3 |
+
from modelscope.pipelines import pipeline
|
4 |
+
from modelscope.utils.constant import Tasks
|
5 |
+
|
6 |
+
text_generation_zh = pipeline(task=Tasks.text_generation, model='baichuan-inc/baichuan-7B',model_revision='v1.0.2')
|
7 |
+
text_generation_zh._model_prepare = True
|
8 |
+
|
9 |
+
def text_generation(input_text):
|
10 |
+
if input_text == "":
|
11 |
+
return ""
|
12 |
+
return text_generation_zh(input_text)['text']
|
13 |
+
|
14 |
+
with gr.Blocks() as demo:
|
15 |
+
gr.Markdown(
|
16 |
+
"""
|
17 |
+
# 百川-7B 模型体验
|
18 |
+
输入文本以查看生成结果。
|
19 |
+
""")
|
20 |
+
inp = gr.Textbox(label="输入prompt")
|
21 |
+
submit = gr.Button("提交")
|
22 |
+
out = gr.Textbox(label="续写结果")
|
23 |
+
submit.click(text_generation, inp, out)
|
24 |
+
|
25 |
+
gr.Markdown("## Text Examples")
|
26 |
+
gr.Examples(
|
27 |
+
["登鹳雀楼->王之涣\n夜雨寄北->", "Hamlet->Shakespeare\nOne Hundred Years of Solitude->"],
|
28 |
+
inp,
|
29 |
+
out,
|
30 |
+
text_generation,
|
31 |
+
cache_examples=True,
|
32 |
+
)
|
33 |
+
|
34 |
+
if __name__ == "__main__":
|
35 |
+
demo.queue().launch()
|