Spaces:
Runtime error
Runtime error
File size: 2,244 Bytes
a38346d 62d145c a38346d 4a6f496 6cef978 a38346d 4a6f496 a38346d 786d709 a38346d |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 |
import gradio as gr
import openai
import os
openai.api_key = os.environ["OPENAI_API_KEY"]
def write_essay(sample_topic, user_topic):
if len(sample_topic) == 0:
sample_topic = user_topic
try:
response = openai.Completion.create(
model="text-davinci-002",
prompt= "Instruction: Write a five-paragraph essay for the following topic:\nSuggested Length: more than 120 words\nTOPIC: " + sample_topic + "\n\nESSAY:",
temperature=0.7,
max_tokens=2000,
top_p=1.0,
frequency_penalty=0.0,
presence_penalty=0.0
)
#print(response)
return response.choices[0].text
except:
return "Invalid Query"
demo = gr.Blocks()
with demo:
gr.Markdown("<h3><center>人工知能から学ぶ、英検作文へのヒント</center></h3>")
gr.Markdown("<h4><center>使い方:トピックを選んで画面左下にある「エッセイ作成」ボタンをクリック</center></h4>")
gr.Markdown("<center>Created by Choimirai School</center>")
with gr.Row():
sample_topic = gr.Radio([
"Will humans live on other planets someday?",
"Japan should become a completely cashless society.",
"Global overpopulation is a serious threat to the future of humankind.",
"Improving relations with other Asian nations should be a priority for the Japanese government.",
"Can renewable energy sources replace fossil fuels?",
"Should democratic nations actively promote the spread of democracy to nondemocratic nations?",
"Agree or disagree, Infectious diseases will become a bigger problem in the coming decades.", ], label= "Choose a sample TOPIC")
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?")
with gr.Row():
written_essay = gr.inputs.Textbox(lines=20, label="Sample Essay written by GPT-3")
b1 = gr.Button("エッセイ作成")
b1.click(write_essay, inputs = [sample_topic, user_topic], outputs = written_essay)
with gr.Row():
gr.Markdown("![visitor badge](https://visitor-badge.glitch.me/badge?page_id=sangmin_eiken-essay-with-gpt3)")
demo.launch(enable_queue=True, debug=True)
|