Mel Seto commited on
Commit
24f0565
·
1 Parent(s): 601a2b1

change app title to "finder"; add literal English translation

Browse files
Files changed (1) hide show
  1. app.py +9 -6
app.py CHANGED
@@ -36,13 +36,15 @@ def generate_idiom_mock(situation: str):
36
  def generate_idiom(situation: str, client):
37
  prompt = f"""
38
  You are a wise assistant. Given a situation, respond with exactly:
39
- 1. A traditional Chinese idiom (成语), which is different from a 四字格, that conveys the idea of the given situation
40
  2. Its pinyin
41
- 3. A short English explanation
 
42
 
43
  Format:
44
  Idiom
45
  Pinyin
 
46
  Explanation
47
 
48
  Situation: {situation}
@@ -60,8 +62,9 @@ Answer:
60
  if len(lines) >= 3:
61
  idiom = lines[0]
62
  pinyin = lines[1]
63
- meaning = " ".join(lines[2:])
64
- explanation = f"{pinyin}<br><br>{meaning}"
 
65
  else:
66
  idiom = generated_text
67
  explanation = ""
@@ -87,7 +90,7 @@ def update_ui(situation):
87
  # ======================
88
  def launch_app():
89
  with gr.Blocks(css="style.css") as demo:
90
- gr.Markdown("# 🎋 Chinese Idioms Generator")
91
 
92
  with gr.Row():
93
  with gr.Column():
@@ -96,7 +99,7 @@ def launch_app():
96
  lines=2,
97
  placeholder="e.g., When facing a big challenge"
98
  )
99
- generate_btn = gr.Button("✨ Generate Idiom")
100
 
101
  # ✅ Example situations
102
  gr.Examples(
 
36
  def generate_idiom(situation: str, client):
37
  prompt = f"""
38
  You are a wise assistant. Given a situation, respond with exactly:
39
+ 1. A traditional Chinese idiom (which includes 成語、俗語、諺語), that conveys the idea of the given situation.
40
  2. Its pinyin
41
+ 3. Its literal English translation
42
+ 4. Explain idiom. Keep explanation to 2-3 concise sentences.
43
 
44
  Format:
45
  Idiom
46
  Pinyin
47
+ Literal translation
48
  Explanation
49
 
50
  Situation: {situation}
 
62
  if len(lines) >= 3:
63
  idiom = lines[0]
64
  pinyin = lines[1]
65
+ translation = lines[2]
66
+ meaning = " ".join(lines[3:])
67
+ explanation = f"{pinyin}<br><br>{translation}<br><br>{meaning}"
68
  else:
69
  idiom = generated_text
70
  explanation = ""
 
90
  # ======================
91
  def launch_app():
92
  with gr.Blocks(css="style.css") as demo:
93
+ gr.Markdown("# 🎋 Chinese Idioms Finder")
94
 
95
  with gr.Row():
96
  with gr.Column():
 
99
  lines=2,
100
  placeholder="e.g., When facing a big challenge"
101
  )
102
+ generate_btn = gr.Button("✨ Find Idiom")
103
 
104
  # ✅ Example situations
105
  gr.Examples(