Spaces:
Sleeping
Sleeping
def generate_topic_sentences(model, max_tokens, sys_content, scenario, eng_level, topic, points, user_generate_topic_sentences_prompt):
Browse files
app.py
CHANGED
@@ -58,6 +58,32 @@ def generate_points(model, max_tokens, sys_content, scenario, eng_level, topic,
|
|
58 |
|
59 |
return content
|
60 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
61 |
|
62 |
with gr.Blocks() as demo:
|
63 |
with gr.Row():
|
@@ -89,7 +115,26 @@ 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 |
|
94 |
|
95 |
with gr.Column():
|
@@ -124,4 +169,19 @@ with gr.Blocks() as demo:
|
|
124 |
outputs=points_output
|
125 |
)
|
126 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
127 |
demo.launch()
|
|
|
58 |
|
59 |
return content
|
60 |
|
61 |
+
def generate_topic_sentences(model, max_tokens, sys_content, scenario, eng_level, topic, points, user_generate_topic_sentences_prompt):
|
62 |
+
"""
|
63 |
+
根据系统提示和用户输入的情境及要点,调用OpenAI API生成相关的主题句及其合理性解释。
|
64 |
+
"""
|
65 |
+
user_content = f"""
|
66 |
+
scenario is {scenario}
|
67 |
+
english level is {eng_level}
|
68 |
+
topic is {topic}
|
69 |
+
points is {points}
|
70 |
+
{user_generate_topic_sentences_prompt}
|
71 |
+
"""
|
72 |
+
messages = [
|
73 |
+
{"role": "system", "content": sys_content},
|
74 |
+
{"role": "user", "content": user_content}
|
75 |
+
]
|
76 |
+
|
77 |
+
request_payload = {
|
78 |
+
"model": model,
|
79 |
+
"messages": messages,
|
80 |
+
"max_tokens": max_tokens,
|
81 |
+
}
|
82 |
+
|
83 |
+
response = OPEN_AI_CLIENT.chat.completions.create(**request_payload)
|
84 |
+
content = response.choices[0].message.content.strip()
|
85 |
+
|
86 |
+
return content
|
87 |
|
88 |
with gr.Blocks() as demo:
|
89 |
with gr.Row():
|
|
|
115 |
user_generate_points_prompt = gr.Textbox(label="Points Prompt", value=default_generate_points_prompt)
|
116 |
generate_points_button = gr.Button("Generate Points")
|
117 |
|
118 |
+
gr.Markdown("## 4. Generate Topic Sentences")
|
119 |
+
points_input = gr.Textbox(label="Points")
|
120 |
+
default_generate_topic_sentences_prompt = """
|
121 |
+
Please provide one appropriate topic sentence that aptly introduces the subject for the given scenario and topic.
|
122 |
+
Additionally, provide two topic sentences that, while related to the topic,
|
123 |
+
would be considered inappropriate or less effective for the specified context.
|
124 |
+
Those sentences must include the three main points:".
|
125 |
+
Use English language and each sentence should not be too long.
|
126 |
+
For each sentence, explain the reason in Traditional Chinese, Taiwan, 繁體中文 zh-TW.
|
127 |
+
|
128 |
+
Make sure the vocabulary you use is at level.
|
129 |
+
Only return the result in JSON format starting as:
|
130 |
+
{{
|
131 |
+
"0": [ {{ "topic-sentence": "#","appropriate": "Y/N", "reason": "#中文解釋" }} ],
|
132 |
+
"1": [ {{ "topic-sentence": "#","appropriate": "Y/N", "reason": "#中文解釋" }} ],
|
133 |
+
"2": [ {{ "topic-sentence": "#","appropriate": "Y/N", "reason": "#中文解釋" }} ]
|
134 |
+
}}
|
135 |
+
"""
|
136 |
+
user_generate_topic_sentences_prompt = gr.Textbox(label="Topic Sentences Prompt", value=default_generate_topic_sentences_prompt)
|
137 |
+
generate_topic_sentences_button = gr.Button("Generate Topic Sentences")
|
138 |
|
139 |
|
140 |
with gr.Column():
|
|
|
169 |
outputs=points_output
|
170 |
)
|
171 |
|
172 |
+
generate_topic_sentences_button.click(
|
173 |
+
fn=generate_topic_sentences,
|
174 |
+
inputs=[
|
175 |
+
model,
|
176 |
+
max_tokens,
|
177 |
+
sys_content_input,
|
178 |
+
scenario_input,
|
179 |
+
eng_level_input,
|
180 |
+
topic_input,
|
181 |
+
points_input,
|
182 |
+
user_generate_topic_sentences_prompt
|
183 |
+
],
|
184 |
+
outputs=topic_output
|
185 |
+
)
|
186 |
+
|
187 |
demo.launch()
|