youngtsai commited on
Commit
8a473de
·
1 Parent(s): 8c415e0

def generate_points(model, max_tokens, sys_content, scenario, eng_level, topic, user_generate_points_prompt):

Browse files
Files changed (1) hide show
  1. app.py +46 -5
app.py CHANGED
@@ -32,6 +32,32 @@ def generate_topic_sentences(model, max_tokens, sys_content, scenario, eng_level
32
 
33
  return content
34
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
35
 
36
  with gr.Blocks() as demo:
37
  with gr.Row():
@@ -45,17 +71,18 @@ with gr.Blocks() as demo:
45
  eng_level_input = gr.Radio(["beginner", "intermediate", "advanced"], label="English Level")
46
 
47
  gr.Markdown("## Generate Topic Sentences")
48
- user_generate_topics_prompt = gr.Textbox(label="User Prompt", value="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.Markdown("## 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(
@@ -71,4 +98,18 @@ with gr.Blocks() as demo:
71
  outputs=topic_output
72
  )
73
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
74
  demo.launch()
 
32
 
33
  return content
34
 
35
+ def generate_points(model, max_tokens, sys_content, scenario, eng_level, topic, user_generate_points_prompt):
36
+ """
37
+ 根据系统提示和用户输入的情境、主题,调用OpenAI API生成相关的主题句。
38
+ """
39
+ user_content = f"""
40
+ scenario is {scenario}
41
+ english level is {eng_level}
42
+ topic is {topic}
43
+ {user_generate_points_prompt}
44
+ """
45
+ messages = [
46
+ {"role": "system", "content": sys_content},
47
+ {"role": "user", "content": user_content}
48
+ ]
49
+
50
+ request_payload = {
51
+ "model": model,
52
+ "messages": messages,
53
+ "max_tokens": max_tokens,
54
+ }
55
+
56
+ response = OPEN_AI_CLIENT.chat.completions.create(**request_payload)
57
+ content = response.choices[0].message.content.strip()
58
+
59
+ return content
60
+
61
 
62
  with gr.Blocks() as demo:
63
  with gr.Row():
 
71
  eng_level_input = gr.Radio(["beginner", "intermediate", "advanced"], label="English Level")
72
 
73
  gr.Markdown("## Generate Topic Sentences")
74
+ user_generate_topics_prompt = gr.Textbox(label="Topics Prompt", value="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.")
75
  generate_topics_button = gr.Button("Generate Topic Sentences")
76
 
77
+ gr.Markdown("## Generate Points")
78
+ topic_input = gr.Textbox(label="Topic")
79
+ user_generate_points_prompt = gr.Textbox(label="Points Prompt", value=" please provide main points to develop in a paragraph about topic in the context of scenario, use simple English language and make sure the vocabulary you use is at eng_level.")
80
+ generate_points_button = gr.Button("Generate Points")
81
 
82
 
83
  with gr.Column():
84
  topic_output = gr.Textbox(label="Generated Topic Sentences")
85
+ points_output = gr.Textbox(label="Generated Points")
86
 
87
 
88
  generate_topics_button.click(
 
98
  outputs=topic_output
99
  )
100
 
101
+ generate_points_button.click(
102
+ fn=generate_points,
103
+ inputs=[
104
+ model,
105
+ max_tokens,
106
+ sys_content_input,
107
+ scenario_input,
108
+ eng_level_input,
109
+ topic_input,
110
+ user_generate_points_prompt
111
+ ],
112
+ outputs=points_output
113
+ )
114
+
115
  demo.launch()