Spaces:
Sleeping
Sleeping
topic_output
Browse files
app.py
CHANGED
@@ -3,17 +3,19 @@ import gradio as gr
|
|
3 |
from openai import OpenAI
|
4 |
|
5 |
|
6 |
-
|
7 |
OPEN_AI_KEY = os.getenv("OPEN_AI_KEY")
|
8 |
OPEN_AI_CLIENT = OpenAI(api_key=OPEN_AI_KEY)
|
9 |
|
10 |
|
11 |
-
|
12 |
-
|
13 |
-
def generate_topic_sentences(sys_content, user_content, model="gpt-4-1106-preview", max_tokens=4000):
|
14 |
"""
|
15 |
根据系统提示和用户输入的情境及主题,调用OpenAI API生成相关的主题句。
|
16 |
"""
|
|
|
|
|
|
|
|
|
|
|
17 |
messages = [
|
18 |
{"role": "system", "content": sys_content},
|
19 |
{"role": "user", "content": user_content}
|
@@ -30,28 +32,43 @@ def generate_topic_sentences(sys_content, user_content, model="gpt-4-1106-previe
|
|
30 |
|
31 |
return content
|
32 |
|
|
|
33 |
with gr.Blocks() as demo:
|
34 |
with gr.Row():
|
35 |
with gr.Column():
|
|
|
|
|
|
|
|
|
|
|
36 |
scenario_input = gr.Textbox(label="Scenario")
|
37 |
-
topic_input = gr.Textbox(label="Topic")
|
38 |
eng_level_input = gr.Radio(["beginner", "intermediate", "advanced"], label="English Level")
|
39 |
-
|
40 |
-
|
|
|
41 |
generate_topics_button = gr.Button("Generate Topic Sentences")
|
|
|
|
|
|
|
|
|
|
|
42 |
|
43 |
with gr.Column():
|
44 |
-
|
45 |
-
|
46 |
-
|
47 |
-
def on_generate_button_click(scenario, topic, eng_level, sys_content):
|
48 |
-
user_content = user_content_template.format(scenario, eng_level)
|
49 |
-
return generate_topic_sentences(sys_content, user_content)
|
50 |
|
51 |
generate_topics_button.click(
|
52 |
-
fn=
|
53 |
-
inputs=[
|
54 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
55 |
)
|
56 |
|
57 |
demo.launch()
|
|
|
3 |
from openai import OpenAI
|
4 |
|
5 |
|
|
|
6 |
OPEN_AI_KEY = os.getenv("OPEN_AI_KEY")
|
7 |
OPEN_AI_CLIENT = OpenAI(api_key=OPEN_AI_KEY)
|
8 |
|
9 |
|
10 |
+
def generate_topic_sentences(model, max_tokens, sys_content,scenario, eng_level user_generate_topics_prompt):
|
|
|
|
|
11 |
"""
|
12 |
根据系统提示和用户输入的情境及主题,调用OpenAI API生成相关的主题句。
|
13 |
"""
|
14 |
+
user_content = f"""
|
15 |
+
scenario is {scenario}
|
16 |
+
english level is {eng_level}
|
17 |
+
{user_generate_topics_prompt}
|
18 |
+
"""
|
19 |
messages = [
|
20 |
{"role": "system", "content": sys_content},
|
21 |
{"role": "user", "content": user_content}
|
|
|
32 |
|
33 |
return content
|
34 |
|
35 |
+
|
36 |
with gr.Blocks() as demo:
|
37 |
with gr.Row():
|
38 |
with gr.Column():
|
39 |
+
# basic inputs
|
40 |
+
gr.Makdown("## Basic Inputs")
|
41 |
+
model = gr.Radio(["gpt-4-1106-preview", "gpt-3.5-turbo"], label="Model")
|
42 |
+
max_tokens = gr.Slider(minimum=50, maximum=4000, default=1000, label="Max Tokens")
|
43 |
+
sys_content_input = gr.Textbox(label="System Prompt", value="You are an English teacher who is practicing with me to improve my English writing skill.")
|
44 |
scenario_input = gr.Textbox(label="Scenario")
|
|
|
45 |
eng_level_input = gr.Radio(["beginner", "intermediate", "advanced"], label="English Level")
|
46 |
+
|
47 |
+
gr.Makdown("## Generate Topic Sentences")
|
48 |
+
user_generate_topics_prompt = "Give me 10 topics relevant to Scenario, for a paragraph. Just the topics, no explanation, use simple English language. Make sure the vocabulary you use is at english level."
|
49 |
generate_topics_button = gr.Button("Generate Topic Sentences")
|
50 |
+
|
51 |
+
# gr.Makdown("## Generate Points")
|
52 |
+
# topic_input = gr.Textbox(label="Topic")
|
53 |
+
# generate_points_button = gr.Button("Generate Points")
|
54 |
+
|
55 |
|
56 |
with gr.Column():
|
57 |
+
topic_output = gr.Textbox(label="Generated Topic Sentences")
|
58 |
+
# points_output = gr.Textbox(label="Generated Points")
|
59 |
+
|
|
|
|
|
|
|
60 |
|
61 |
generate_topics_button.click(
|
62 |
+
fn=generate_topic_sentences,
|
63 |
+
inputs=[
|
64 |
+
model,
|
65 |
+
max_tokens,
|
66 |
+
sys_content_input,
|
67 |
+
scenario_input,
|
68 |
+
eng_level_input,
|
69 |
+
user_generate_topics_prompt
|
70 |
+
],
|
71 |
+
outputs=topic_output
|
72 |
)
|
73 |
|
74 |
demo.launch()
|