AUST001 commited on
Commit
91f0fdf
·
1 Parent(s): 029837d

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +39 -0
app.py CHANGED
@@ -0,0 +1,39 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import openai
2
+ import gradio as gr
3
+ import random
4
+
5
+
6
+ openai.api_key = random.choice(['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',
7
+ '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',
8
+ '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',
9
+ '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',
10
+ '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',
11
+ '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',
12
+ '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',
13
+ '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',
14
+ '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',
15
+ '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',
16
+ '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'])
17
+
18
+ def completion(prompt):
19
+ response = openai.Completion.create(
20
+ engine="text-davinci-003",
21
+ prompt=prompt,
22
+ max_tokens=1024,
23
+ n=1,
24
+ stop=None,
25
+ temperature=0.5
26
+ )
27
+ return response.choices[0].text[2:]
28
+
29
+ def greet(question):
30
+ if question[-3:]=='???' or question[-3:]=='???':
31
+ return completion('Please translate this passage into German and then into Chinese.\n'+question[:-3])
32
+ else:
33
+ return 'Unknown error'
34
+
35
+ demo = gr.Interface(fn=greet, inputs=gr.Textbox(lines=20, placeholder='Please enter your question'), outputs=gr.Textbox(lines=20, placeholder='Waiting for AI to answer'))
36
+
37
+ if __name__ == "__main__":
38
+ # demo.launch(share='True')
39
+ demo.launch()