Spaces:
Sleeping
Sleeping
File size: 1,404 Bytes
15de163 445694f cea0ede 445694f 65a0752 445694f 7fa65ee 21bc572 445694f 21bc572 445694f |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
#pip install openai
import openai
import gradio as gr
openai.api_key = ('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')
def generate_text(prompt):
completions = openai.Completion.create(
engine="text-davinci-003",
prompt=prompt,
max_tokens=1024,
n=1,
stop=None,
temperature=0.5,
)
message = completions.choices[0].text
return message.strip()
def greet(ask):
return generate_text(ask)
#demo = gr.Interface(fn=greet,inputs=gr.Textbox(lines=5, placeholder="想问什么?"),outputs=gr.Textbox(lines=3, placeholder="等待问答。。。"),) + gr.Accordion("欢迎━(*`∀´*)ノ亻!!") + gr.Markdown("这是随作闲出p做的网站,会特别特别慢!随便用吧。。。")
with gr.Blocks() as demo:
gr.Markdown("这是一个以openai的text-davinci-003文本模型为基础的在api请求的基础上搭建的简易网站,非商业用途")
with gr.Tab("问答"):
text_input = gr.Textbox(lines=5, placeholder="想问什么?")
text_output = gr.Textbox(lines=3, placeholder="等待问答。。。")
text_button = gr.Button("发送")
with gr.Accordion("欢迎━(*`∀´*)ノ亻!!"):
gr.Markdown("ps:这是随作闲出p做的网站,会特别特别慢!随便用吧。。。")
text_button.click(fn=greet,inputs=text_input, outputs=text_output)
demo.launch()
|