File size: 715 Bytes
93f9bce
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
import gradio as gr
from transformers import pipeline

# 加载模型和tokenizer
generator = pipeline('text-generation', model='hfl/chinese-llama-2-1.3b')

# 定义预测函数
def predict(text,password,temperature):
    if password != "123":
      return "Password wrong"
    else:
      result = generator(text, max_length=400, num_return_sequences=1 , temperature=float(temperature))
      return result[0]['generated_text']

# 创建Gradio界面
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")

# 启动Gradio界面
demo.launch(share=True)