youngtsai commited on
Commit
daa5f8e
·
1 Parent(s): a0a3ddc

def generate_supporting_sentences(model, max_tokens, sys_content, scenario, eng_level, topic, points, topic_sentence, user_generate_supporting_sentences_prompt):

Browse files
Files changed (1) hide show
  1. app.py +59 -1
app.py CHANGED
@@ -113,6 +113,34 @@ def parse_and_display_topic_sentences(json_data):
113
 
114
  return formatted_text
115
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
116
  with gr.Blocks() as demo:
117
  with gr.Row():
118
  with gr.Column():
@@ -164,11 +192,25 @@ with gr.Blocks() as demo:
164
  user_generate_topic_sentences_prompt = gr.Textbox(label="Topic Sentences Prompt", value=default_generate_topic_sentences_prompt)
165
  generate_topic_sentences_button = gr.Button("Generate Topic Sentences")
166
 
167
-
 
 
 
 
 
 
 
 
 
 
 
 
 
168
  with gr.Column():
169
  topic_output = gr.Textbox(label="Generated Topic")
170
  points_output = gr.Textbox(label="Generated Points")
171
  topic_sentence_output = gr.Textbox(label="Generated Topic Sentences")
 
172
 
173
 
174
  generate_topics_button.click(
@@ -213,4 +255,20 @@ with gr.Blocks() as demo:
213
  outputs=topic_sentence_output
214
  )
215
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
216
  demo.launch()
 
113
 
114
  return formatted_text
115
 
116
+ def generate_supporting_sentences(model, max_tokens, sys_content, scenario, eng_level, topic, points, topic_sentence, user_generate_supporting_sentences_prompt):
117
+ """
118
+ 根据系统提示和用户输入的情境、主题、要点、主题句,调用OpenAI API生成相关的支持句。
119
+ """
120
+ user_content = f"""
121
+ scenario is {scenario}
122
+ english level is {eng_level}
123
+ topic is {topic}
124
+ points is {points}
125
+ topic sentence is {topic_sentence}
126
+ {user_generate_supporting_sentences_prompt}
127
+ """
128
+ messages = [
129
+ {"role": "system", "content": sys_content},
130
+ {"role": "user", "content": user_content}
131
+ ]
132
+
133
+ request_payload = {
134
+ "model": model,
135
+ "messages": messages,
136
+ "max_tokens": max_tokens,
137
+ }
138
+
139
+ response = OPEN_AI_CLIENT.chat.completions.create(**request_payload)
140
+ content = response.choices[0].message.content.strip()
141
+
142
+ return content
143
+
144
  with gr.Blocks() as demo:
145
  with gr.Row():
146
  with gr.Column():
 
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.
199
+ Please assist me by "Developing supporting detials" based on the keyword: points to write three sentences as an example.
200
+ - Make sure any revised vocabulary aligns with the eng_level.
201
+ - Guidelines for Length and Complexity:
202
+ Please keep the example concise and straightforward,
203
+ avoiding overly technical language.
204
+ Total word-count is around 50.
205
+ """
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")
212
  topic_sentence_output = gr.Textbox(label="Generated Topic Sentences")
213
+ supporting_sentences_output = gr.Textbox(label="Generated Supporting Sentences")
214
 
215
 
216
  generate_topics_button.click(
 
255
  outputs=topic_sentence_output
256
  )
257
 
258
+ generate_supporting_sentences_button.click(
259
+ fn=generate_supporting_sentences,
260
+ inputs=[
261
+ model,
262
+ max_tokens,
263
+ sys_content_input,
264
+ scenario_input,
265
+ eng_level_input,
266
+ topic_input,
267
+ points_input,
268
+ topic_sentence_input,
269
+ user_generate_supporting_sentences_prompt
270
+ ],
271
+ outputs=supporting_sentences_output
272
+ )
273
+
274
  demo.launch()