Spaces:
Sleeping
Sleeping
Step 2. 確定段落主題
Browse files
app.py
CHANGED
@@ -45,9 +45,9 @@ def generate_topics(model, max_tokens, sys_content, scenario, eng_level, user_ge
|
|
45 |
topics = json.loads(content)["topics"]
|
46 |
topics_text = json.dumps(topics)
|
47 |
|
48 |
-
|
49 |
|
50 |
-
return topics_text,
|
51 |
|
52 |
def update_topic_input(topic):
|
53 |
return topic
|
@@ -304,39 +304,69 @@ def paragraph_save_and_tts(paragraph_text):
|
|
304 |
# Handle the error appropriately (e.g., return an error message or a default audio path)
|
305 |
return paragraph_text, None
|
306 |
|
307 |
-
|
308 |
-
.btn-max-length { max-width: 200px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
|
309 |
-
.btn-highlight { border-color: yellow; }
|
310 |
-
"""
|
311 |
-
with gr.Blocks(css=CSS) as demo:
|
312 |
with gr.Row():
|
313 |
with gr.Column():
|
314 |
# basic inputs
|
315 |
-
gr.Markdown("## 1. Basic Inputs")
|
316 |
model = gr.Radio(["gpt-4o", "gpt-3.5-turbo"], label="Model", value="gpt-4o", visible=False)
|
317 |
max_tokens = gr.Slider(minimum=50, maximum=4000, value=4000, label="Max Tokens", visible=False)
|
318 |
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.", visible=False)
|
319 |
-
scenario_input = gr.Textbox(label="Scenario")
|
320 |
-
eng_level_input = gr.Radio(["beginner", "intermediate", "advanced"], label="English Level", value="beginner")
|
321 |
|
322 |
-
gr.
|
323 |
-
|
324 |
-
|
325 |
-
|
326 |
-
|
327 |
-
|
328 |
-
|
329 |
-
|
330 |
-
|
331 |
-
|
332 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
333 |
|
|
|
|
|
|
|
334 |
with gr.Row():
|
335 |
with gr.Column():
|
336 |
-
|
337 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
338 |
with gr.Column():
|
339 |
-
generate_topics_button = gr.Button("
|
340 |
topic_output = gr.Textbox(label="AI Generated Topic 主題", visible=True, value=[])
|
341 |
|
342 |
@gr.render(inputs=topic_output)
|
|
|
45 |
topics = json.loads(content)["topics"]
|
46 |
topics_text = json.dumps(topics)
|
47 |
|
48 |
+
is_visible_false = gr.update(visible=False)
|
49 |
|
50 |
+
return topics_text, is_visible_false
|
51 |
|
52 |
def update_topic_input(topic):
|
53 |
return topic
|
|
|
304 |
# Handle the error appropriately (e.g., return an error message or a default audio path)
|
305 |
return paragraph_text, None
|
306 |
|
307 |
+
with gr.Blocks(theme=gr.themes.Soft(primary_hue=gr.themes.colors.blue, secondary_hue=gr.themes.colors.orange)) as demo:
|
|
|
|
|
|
|
|
|
308 |
with gr.Row():
|
309 |
with gr.Column():
|
310 |
# basic inputs
|
|
|
311 |
model = gr.Radio(["gpt-4o", "gpt-3.5-turbo"], label="Model", value="gpt-4o", visible=False)
|
312 |
max_tokens = gr.Slider(minimum=50, maximum=4000, value=4000, label="Max Tokens", visible=False)
|
313 |
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.", visible=False)
|
|
|
|
|
314 |
|
315 |
+
with gr.Row():
|
316 |
+
eng_level_input = gr.Radio(["beginner", "intermediate", "advanced"], label="English Level", value="beginner")
|
317 |
+
with gr.Row():
|
318 |
+
gr.Markdown("# Step 1. 你今天想練習寫什麼呢?")
|
319 |
+
with gr.Row():
|
320 |
+
gr.Markdown("""## 寫作的主題與讀者、寫作的目的、文章的風格、長度、範圍、以及作者的專業知識等都有關係。因為不容易找主題,所以利用兩階段方式來找主題。特為較無英文寫作經驗的 基礎級使用者 提供多種大範圍情境,待篩選情境後,下一步再來決定明確的主題。""")
|
321 |
+
with gr.Row():
|
322 |
+
scenario_values = [
|
323 |
+
"Health",
|
324 |
+
"Thanksgiving",
|
325 |
+
"Halloween",
|
326 |
+
"moon festival in Taiwan",
|
327 |
+
"School and Learning",
|
328 |
+
"Travel and Places",
|
329 |
+
"Family and Friends",
|
330 |
+
"Hobbies and Leisure Activities",
|
331 |
+
"Health and Exercise",
|
332 |
+
"Personal Experiences",
|
333 |
+
"My Future Goals",
|
334 |
+
"School Life",
|
335 |
+
"Pets",
|
336 |
+
"A Problem and Solution",
|
337 |
+
"Holidays and Celebrations",
|
338 |
+
"My Favorite Cartoon/Anime"
|
339 |
+
]
|
340 |
+
scenario_input = gr.Dropdown(label="先選擇一個大範圍的情境:", choices=scenario_values, value="Health")
|
341 |
|
342 |
+
# Step 2. 確定段落主題
|
343 |
+
with gr.Row():
|
344 |
+
gr.Markdown("# Step 2. 確定段落主題")
|
345 |
with gr.Row():
|
346 |
with gr.Column():
|
347 |
+
gr.Markdown("""## 主題是整個段落要探討、闡述的主要議題。確定主題對於段落的架構、內容非常重要,幫助讀者預期段落的內容,增加閱讀的速度及理解度。寫作過程中,掌握主題可以幫助作者有效傳達自己的想法和觀點,幫助讀者更容易理解。""")
|
348 |
+
with gr.Column():
|
349 |
+
with gr.Accordion("參考指引:情境與主題如何搭配呢?", open=False):
|
350 |
+
gr.Markdown("""
|
351 |
+
例如,情境是 `School & Learning` ,你可以依照自己的興趣、背景及經驗,決定合適的主題,像是:`My First Day at School` 或 `The Role of Internet in Learning`
|
352 |
+
例如,情境是 `Climate Change`,相關主題可能是 `Global Warming` 或 `Extreme Weather Events`
|
353 |
+
""")
|
354 |
+
with gr.Row(visible=False) as topic_params:
|
355 |
+
default_generate_topics_prompt = """
|
356 |
+
Give me 10 topics relevant to Scenario,
|
357 |
+
for a paragraph. Just the topics, no explanation, use simple English language.
|
358 |
+
Make sure the vocabulary you use is at english level.
|
359 |
+
output use JSON
|
360 |
+
|
361 |
+
EXAMPLE:
|
362 |
+
"topics":["topic1", "topic2", "topic3", "topic4", "topic5", "topic6", "topic7", "topic8", "topic9", "topic10"]
|
363 |
+
"""
|
364 |
+
user_generate_topics_prompt = gr.Textbox(label="Topics Prompt", value=default_generate_topics_prompt, visible=False)
|
365 |
+
with gr.Row():
|
366 |
+
with gr.Column():
|
367 |
+
topic_input = gr.Textbox(label="選擇合適的主題:", interactive=False)
|
368 |
with gr.Column():
|
369 |
+
generate_topics_button = gr.Button("使用 🪄 JUTOR 產生 10 個段落主題,再挑選一個來練習吧!", variant="primary")
|
370 |
topic_output = gr.Textbox(label="AI Generated Topic 主題", visible=True, value=[])
|
371 |
|
372 |
@gr.render(inputs=topic_output)
|