Spaces:
Sleeping
Sleeping
Upload 2 files
Browse files- app.py +19 -0
- requirements.txt +3 -0
app.py
ADDED
@@ -0,0 +1,19 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
from transformers import pipeline
|
3 |
+
|
4 |
+
# 加载模型和tokenizer
|
5 |
+
generator = pipeline('text-generation', model='hfl/chinese-llama-2-1.3b')
|
6 |
+
|
7 |
+
# 定义预测函数
|
8 |
+
def predict(text,password,temperature):
|
9 |
+
if password != "123":
|
10 |
+
return "Password wrong"
|
11 |
+
else:
|
12 |
+
result = generator(text, max_length=400, num_return_sequences=1 , temperature=float(temperature))
|
13 |
+
return result[0]['generated_text']
|
14 |
+
|
15 |
+
# 创建Gradio界面
|
16 |
+
demo = gr.Interface(fn=predict,inputs=[gr.Textbox(label="Text"),gr.Textbox(label="Password"),gr.Textbox(label="temperature")],outputs="text",title="Chinese-llama-2-1.3b",description="input your text")
|
17 |
+
|
18 |
+
# 启动Gradio界面
|
19 |
+
demo.launch(share=True)
|
requirements.txt
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
gradio==3.16.2
|
2 |
+
transformers==4.21.2
|
3 |
+
torch==1.12.1
|