Sangmin commited on
Commit
a38346d
1 Parent(s): b3ffc3a

Initial commit

Browse files
Files changed (1) hide show
  1. app.py +50 -0
app.py ADDED
@@ -0,0 +1,50 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ import openai
3
+ import os
4
+
5
+ openai.api_key = os.environ["OPENAI_API_KEY"]
6
+
7
+ def write_essay(sample_topic, user_topic):
8
+ if len(sample_topic) == 0:
9
+ sample_topic = user_topic
10
+ try:
11
+ response = openai.Completion.create(
12
+ model="text-davinci-002",
13
+ prompt= "Instruction: Write a five-paragraph essay for the following topic:\nSuggested Length: more than 120 words\nTOPIC: " + sample_topic + "\n\nESSAY:",
14
+ temperature=0.7,
15
+ max_tokens=500,
16
+ top_p=1.0,
17
+ frequency_penalty=0.0,
18
+ presence_penalty=0.0
19
+ )
20
+ #print(response)
21
+ return response.choices[0].text
22
+ except:
23
+ return "Invalid Query"
24
+
25
+ demo = gr.Blocks()
26
+
27
+ with demo:
28
+ gr.Markdown("<h2><center>Eiken Essay with GPT-3</center></h2>")
29
+ gr.Markdown("<h4><center>Enter a topic for Eiken essay. GPT-3 will, then, write a sample essay for you.</center></h4>")
30
+ gr.Markdown("<center>Brought to you by Choimirai School</center>")
31
+
32
+ with gr.Row():
33
+ sample_topic = gr.Radio([
34
+ "Will humans live on other planets someday?",
35
+ "Japan should become a completely cashless society.",
36
+ "Global overpopulation is a serious threat to the future of humankind.",
37
+ "Improving relations with other Asian nations should be a priority for the Japanese government.",
38
+ "Can renewable energy sources replace fossil fuels?",
39
+ "Should democratic nations actively promote the spread of democracy to nondemocratic nations?",
40
+ "Agree or disagree, Infectious diseases will become a bigger problem in the coming decades.", ], label= "Choose a sample TOPIC")
41
+
42
+ user_topic = gr.Textbox(label="Or, write your own topic for Eiken essay.", value="Will fossil fuels such as oil and gas still be the world's main source of energy in the coming decades?")
43
+
44
+ with gr.Row():
45
+ written_essay = gr.inputs.Textbox(lines=20, label="Sample Essay written by GPT-3")
46
+
47
+ b1 = gr.Button("Write Essay")
48
+ b1.click(write_essay, inputs = [sample_topic, user_topic], outputs = written_essay)
49
+
50
+ demo.launch(enable_queue=True, debug=True)