openai_api / app.py
lesesuizuo's picture
Update app.py
7fa65ee
raw
history blame contribute delete
No virus
1.4 kB
#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()