jadend commited on
Commit
20267e3
·
1 Parent(s): d60f818

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +30 -0
app.py ADDED
@@ -0,0 +1,30 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import os
2
+ import openai
3
+ import gradio as gr
4
+
5
+ user_db = {os.environ["admin_username"]: os.environ["admin_password"], os.environ["username"]: os.environ["password"]}
6
+
7
+ def mr_bot(premise, tokens, temperature):
8
+ openai.api_key = os.environ["API_TOKEN"]
9
+ response = openai.Completion.create(
10
+ model="text-davinci-003",
11
+ prompt=premise,
12
+ max_tokens=tokens,
13
+ temperature=temperature
14
+ )
15
+ return response['choices'][0]["text"]
16
+
17
+ description = "Ask Mr. Bot a question or give him a command."
18
+
19
+ demo = gr.Interface(fn=mr_bot,
20
+ inputs=["text", gr.Slider(1, 800), gr.Slider(0, 1)],
21
+ outputs="text",
22
+ title="Mr. Bot",
23
+ description=description,
24
+ examples = [["Write me a rap song about how the price of rent is too high."]]
25
+ )
26
+
27
+ if __name__ == "__main__":
28
+ demo.launch(enable_queue=False,
29
+ auth=lambda u, p: user_db.get(u) == p,
30
+ auth_message="This is a welcome message")