Spaces:
Running
Running
lesesuizuo
commited on
Commit
•
445694f
1
Parent(s):
c182a61
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,40 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
!pip install openai
|
2 |
+
import openai
|
3 |
+
import gradio as gr
|
4 |
+
|
5 |
+
openai.api_key = ('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')
|
6 |
+
|
7 |
+
def generate_text(prompt):
|
8 |
+
completions = openai.Completion.create(
|
9 |
+
engine="text-ada-001",
|
10 |
+
prompt=prompt,
|
11 |
+
max_tokens=256,
|
12 |
+
n=1,
|
13 |
+
stop=None,
|
14 |
+
temperature=0.5,
|
15 |
+
)
|
16 |
+
|
17 |
+
message = completions.choices[0].text
|
18 |
+
return message.strip()
|
19 |
+
|
20 |
+
def greet(ask):
|
21 |
+
return generate_text(ask)
|
22 |
+
|
23 |
+
print(greet)
|
24 |
+
|
25 |
+
#demo = gr.Interface(fn=greet,inputs=gr.Textbox(lines=5, placeholder="想问什么?"),outputs=gr.Textbox(lines=3, placeholder="等待问答。。。"),) + gr.Accordion("欢迎━(*`∀´*)ノ亻!!") + gr.Markdown("这是随作闲出p做的网站,会特别特别慢!随便用吧。。。")
|
26 |
+
with gr.Blocks() as demo:
|
27 |
+
gr.Markdown("你好")
|
28 |
+
with gr.Tab("Text"):
|
29 |
+
text_input = gr.Textbox(lines=5, placeholder="想问什么?")
|
30 |
+
text_output = gr.Textbox(lines=3, placeholder="等待问答。。。")
|
31 |
+
text_button = gr.Button("Flip")
|
32 |
+
|
33 |
+
with gr.Accordion("欢迎━(*`∀´*)ノ亻!!"):
|
34 |
+
gr.Markdown("ps:这是随作闲出p做的网站,会特别特别慢!随便用吧。。。")
|
35 |
+
|
36 |
+
text_button.click(fn=greet,inputs=text_input, outputs=text_output)
|
37 |
+
demo.launch()
|
38 |
+
|
39 |
+
|
40 |
+
|