youngtsai commited on
Commit
380a1ee
·
1 Parent(s): 6a96ef9

年級:{grade}

Browse files
Files changed (1) hide show
  1. app.py +7 -2
app.py CHANGED
@@ -8,13 +8,15 @@ import json
8
  OPEN_AI_KEY = os.getenv("OPEN_AI_KEY")
9
  OPEN_AI_CLIENT = OpenAI(api_key=OPEN_AI_KEY)
10
 
11
- def generate_article(reference_text, lesson_title, seed_words, derivative_words, prompt_text):
12
  # 結合用戶輸入來形成最終的prompt
13
  reference_text = f"""
14
  文章參考:{reference_text}
15
  文章標題:{lesson_title}
16
  關鍵詞:{seed_words}
17
  衍生詞:{derivative_words}
 
 
18
  """
19
 
20
 
@@ -48,6 +50,9 @@ with gr.Blocks() as demo:
48
  lesson_title = gr.Textbox(label="課程標題", placeholder="輸入課程標題...")
49
  seed_words = gr.Textbox(label="文章生字", placeholder="貼上文章生字...", lines=2)
50
  derivative_words = gr.Textbox(label="衍生生字", placeholder="貼上衍生生字...", lines=2)
 
 
 
51
  prompt_text = gr.Textbox(label="prompt的文字", placeholder="輸入或修改prompt的文字...")
52
  generate_article_btn = gr.Button(value="生成文章")
53
 
@@ -56,7 +61,7 @@ with gr.Blocks() as demo:
56
 
57
  generate_article_btn.click(
58
  generate_article,
59
- inputs =[reference_text, lesson_title, seed_words, derivative_words, prompt_text],
60
  outputs=new_article
61
  )
62
 
 
8
  OPEN_AI_KEY = os.getenv("OPEN_AI_KEY")
9
  OPEN_AI_CLIENT = OpenAI(api_key=OPEN_AI_KEY)
10
 
11
+ def generate_article(reference_text, lesson_title, seed_words, derivative_words, grade, word_count, prompt_text):
12
  # 結合用戶輸入來形成最終的prompt
13
  reference_text = f"""
14
  文章參考:{reference_text}
15
  文章標題:{lesson_title}
16
  關鍵詞:{seed_words}
17
  衍生詞:{derivative_words}
18
+ 年級:{grade}
19
+ 文章字數限制:{word_count}
20
  """
21
 
22
 
 
50
  lesson_title = gr.Textbox(label="課程標題", placeholder="輸入課程標題...")
51
  seed_words = gr.Textbox(label="文章生字", placeholder="貼上文章生字...", lines=2)
52
  derivative_words = gr.Textbox(label="衍生生字", placeholder="貼上衍生生字...", lines=2)
53
+ with gr.Row():
54
+ grade = gr.Dropdown(label="年級", choices=["一年級", "二年級", "三年級", "四年級", "五年級", "六年級"], default="一年級")
55
+ word_count = gr.Textbox(label="文章字數", placeholder="輸入文章字數...", type="number")
56
  prompt_text = gr.Textbox(label="prompt的文字", placeholder="輸入或修改prompt的文字...")
57
  generate_article_btn = gr.Button(value="生成文章")
58
 
 
61
 
62
  generate_article_btn.click(
63
  generate_article,
64
+ inputs =[reference_text, lesson_title, seed_words, derivative_words, grade, word_count, prompt_text],
65
  outputs=new_article
66
  )
67