youngtsai commited on
Commit
cc83ab8
·
1 Parent(s): bbacb5a

gr.Markdown("## 6. Conclusion sentence 結論句")

Browse files
Files changed (1) hide show
  1. app.py +61 -1
app.py CHANGED
@@ -141,6 +141,34 @@ def generate_supporting_sentences(model, max_tokens, sys_content, scenario, eng_
141
 
142
  return content
143
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
144
  with gr.Blocks() as demo:
145
  with gr.Row():
146
  with gr.Column():
@@ -192,7 +220,7 @@ with gr.Blocks() as demo:
192
  user_generate_topic_sentences_prompt = gr.Textbox(label="Topic Sentences Prompt", value=default_generate_topic_sentences_prompt)
193
  generate_topic_sentences_button = gr.Button("Generate Topic Sentences")
194
 
195
- gr.Markdown("## 5. Generate Supporting Sentence")
196
  topic_sentence_input = gr.Textbox(label="Topic Sentences")
197
  default_generate_supporting_sentences_prompt = """
198
  I'm aiming to improve my writing. I have a topic sentence as topic_sentence_input.
@@ -206,6 +234,22 @@ with gr.Blocks() as demo:
206
  user_generate_supporting_sentences_prompt = gr.Textbox(label="Supporting Sentences Prompt", value=default_generate_supporting_sentences_prompt)
207
  generate_supporting_sentences_button = gr.Button("Generate Supporting Sentences")
208
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
209
  with gr.Column():
210
  topic_output = gr.Textbox(label="Generated Topic 主題")
211
  points_output = gr.Textbox(label="Generated Points 要點")
@@ -271,4 +315,20 @@ with gr.Blocks() as demo:
271
  outputs=supporting_sentences_output
272
  )
273
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
274
  demo.launch()
 
141
 
142
  return content
143
 
144
+ def generate_conclusion_sentences(model, max_tokens, sys_content, scenario, eng_level, topic, points, topic_sentence, user_generate_conclusion_sentence_prompt):
145
+ """
146
+ 根据系统提示和用户输入的情境、主题、要点、主题句,调用OpenAI API生成相关的结论句。
147
+ """
148
+ user_content = f"""
149
+ scenario is {scenario}
150
+ english level is {eng_level}
151
+ topic is {topic}
152
+ points is {points}
153
+ topic sentence is {topic_sentence}
154
+ {user_generate_conclusion_sentence_prompt}
155
+ """
156
+ messages = [
157
+ {"role": "system", "content": sys_content},
158
+ {"role": "user", "content": user_content}
159
+ ]
160
+
161
+ request_payload = {
162
+ "model": model,
163
+ "messages": messages,
164
+ "max_tokens": max_tokens,
165
+ }
166
+
167
+ response = OPEN_AI_CLIENT.chat.completions.create(**request_payload)
168
+ content = response.choices[0].message.content.strip()
169
+
170
+ return content
171
+
172
  with gr.Blocks() as demo:
173
  with gr.Row():
174
  with gr.Column():
 
220
  user_generate_topic_sentences_prompt = gr.Textbox(label="Topic Sentences Prompt", value=default_generate_topic_sentences_prompt)
221
  generate_topic_sentences_button = gr.Button("Generate Topic Sentences")
222
 
223
+ gr.Markdown("## 5. Generate Supporting Sentence 支持句")
224
  topic_sentence_input = gr.Textbox(label="Topic Sentences")
225
  default_generate_supporting_sentences_prompt = """
226
  I'm aiming to improve my writing. I have a topic sentence as topic_sentence_input.
 
234
  user_generate_supporting_sentences_prompt = gr.Textbox(label="Supporting Sentences Prompt", value=default_generate_supporting_sentences_prompt)
235
  generate_supporting_sentences_button = gr.Button("Generate Supporting Sentences")
236
 
237
+ gr.Markdown("## 6. Conclusion sentence 結論句")
238
+ supporting_sentences_input = gr.Textbox(label="Supporting Sentences")
239
+ default_generate_conclusion_sentence_prompt = """
240
+ I'm aiming to improve my writing.
241
+ By the topic sentence, please assist me by "Developing conclusion sentences"
242
+ based on keywords of points to finish a paragrpah as an example.
243
+ - Make sure any revised vocabulary aligns with the correctly level.
244
+ - Guidelines for Length and Complexity:
245
+ Please keep the example concise and straightforward,
246
+ avoiding overly technical language.
247
+ Total word-count is around 20.
248
+ """
249
+ user_generate_conclusion_sentence_prompt = gr.Textbox(label="Conclusion Sentence Prompt", value=default_generate_conclusion_sentence_prompt)
250
+ generate_conclusion_sentence_button = gr.Button("Generate Conclusion Sentence")
251
+
252
+
253
  with gr.Column():
254
  topic_output = gr.Textbox(label="Generated Topic 主題")
255
  points_output = gr.Textbox(label="Generated Points 要點")
 
315
  outputs=supporting_sentences_output
316
  )
317
 
318
+ generate_conclusion_sentence_button.click(
319
+ fn=generate_conclusion_sentences,
320
+ inputs=[
321
+ model,
322
+ max_tokens,
323
+ sys_content_input,
324
+ scenario_input,
325
+ eng_level_input,
326
+ topic_input,
327
+ points_input,
328
+ topic_sentence_input,
329
+ user_generate_conclusion_sentence_prompt
330
+ ],
331
+ outputs=supporting_sentences_output
332
+ )
333
+
334
  demo.launch()