Spaces:
Sleeping
Sleeping
generate_topics
Browse files
app.py
CHANGED
@@ -7,7 +7,7 @@ OPEN_AI_KEY = os.getenv("OPEN_AI_KEY")
|
|
7 |
OPEN_AI_CLIENT = OpenAI(api_key=OPEN_AI_KEY)
|
8 |
|
9 |
|
10 |
-
def
|
11 |
"""
|
12 |
根据系统提示和用户输入的情境及主题,调用OpenAI API生成相关的主题句。
|
13 |
"""
|
@@ -63,14 +63,14 @@ with gr.Blocks() as demo:
|
|
63 |
with gr.Row():
|
64 |
with gr.Column():
|
65 |
# basic inputs
|
66 |
-
gr.Markdown("## Basic Inputs")
|
67 |
model = gr.Radio(["gpt-4-1106-preview", "gpt-3.5-turbo"], label="Model", value="gpt-4-1106-preview")
|
68 |
max_tokens = gr.Slider(minimum=50, maximum=4000, value=1000, label="Max Tokens")
|
69 |
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.")
|
70 |
scenario_input = gr.Textbox(label="Scenario")
|
71 |
eng_level_input = gr.Radio(["beginner", "intermediate", "advanced"], label="English Level", value="beginner")
|
72 |
|
73 |
-
gr.Markdown("## Generate Topic
|
74 |
default_generate_topics_prompt = """
|
75 |
Give me 10 topics relevant to Scenario,
|
76 |
for a paragraph. Just the topics, no explanation, use simple English language.
|
@@ -79,7 +79,7 @@ with gr.Blocks() as demo:
|
|
79 |
user_generate_topics_prompt = gr.Textbox(label="Topics Prompt", value=default_generate_topics_prompt)
|
80 |
generate_topics_button = gr.Button("Generate Topic Sentences")
|
81 |
|
82 |
-
gr.Markdown("## Generate Points")
|
83 |
topic_input = gr.Textbox(label="Topic")
|
84 |
default_generate_points_prompt = """
|
85 |
Please provide main points to develop in a paragraph about topic in the context of scenario,
|
@@ -89,6 +89,8 @@ with gr.Blocks() as demo:
|
|
89 |
user_generate_points_prompt = gr.Textbox(label="Points Prompt", value=default_generate_points_prompt)
|
90 |
generate_points_button = gr.Button("Generate Points")
|
91 |
|
|
|
|
|
92 |
|
93 |
with gr.Column():
|
94 |
topic_output = gr.Textbox(label="Generated Topic Sentences")
|
@@ -96,7 +98,7 @@ with gr.Blocks() as demo:
|
|
96 |
|
97 |
|
98 |
generate_topics_button.click(
|
99 |
-
fn=
|
100 |
inputs=[
|
101 |
model,
|
102 |
max_tokens,
|
|
|
7 |
OPEN_AI_CLIENT = OpenAI(api_key=OPEN_AI_KEY)
|
8 |
|
9 |
|
10 |
+
def generate_topics(model, max_tokens, sys_content, scenario, eng_level, user_generate_topics_prompt):
|
11 |
"""
|
12 |
根据系统提示和用户输入的情境及主题,调用OpenAI API生成相关的主题句。
|
13 |
"""
|
|
|
63 |
with gr.Row():
|
64 |
with gr.Column():
|
65 |
# basic inputs
|
66 |
+
gr.Markdown("## 1. Basic Inputs")
|
67 |
model = gr.Radio(["gpt-4-1106-preview", "gpt-3.5-turbo"], label="Model", value="gpt-4-1106-preview")
|
68 |
max_tokens = gr.Slider(minimum=50, maximum=4000, value=1000, label="Max Tokens")
|
69 |
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.")
|
70 |
scenario_input = gr.Textbox(label="Scenario")
|
71 |
eng_level_input = gr.Radio(["beginner", "intermediate", "advanced"], label="English Level", value="beginner")
|
72 |
|
73 |
+
gr.Markdown("## 2. Generate Topic")
|
74 |
default_generate_topics_prompt = """
|
75 |
Give me 10 topics relevant to Scenario,
|
76 |
for a paragraph. Just the topics, no explanation, use simple English language.
|
|
|
79 |
user_generate_topics_prompt = gr.Textbox(label="Topics Prompt", value=default_generate_topics_prompt)
|
80 |
generate_topics_button = gr.Button("Generate Topic Sentences")
|
81 |
|
82 |
+
gr.Markdown("## 3. Generate Points")
|
83 |
topic_input = gr.Textbox(label="Topic")
|
84 |
default_generate_points_prompt = """
|
85 |
Please provide main points to develop in a paragraph about topic in the context of scenario,
|
|
|
89 |
user_generate_points_prompt = gr.Textbox(label="Points Prompt", value=default_generate_points_prompt)
|
90 |
generate_points_button = gr.Button("Generate Points")
|
91 |
|
92 |
+
|
93 |
+
|
94 |
|
95 |
with gr.Column():
|
96 |
topic_output = gr.Textbox(label="Generated Topic Sentences")
|
|
|
98 |
|
99 |
|
100 |
generate_topics_button.click(
|
101 |
+
fn=generate_topics,
|
102 |
inputs=[
|
103 |
model,
|
104 |
max_tokens,
|