Mel Seto
commited on
Commit
·
49ea7ef
1
Parent(s):
a1e849a
use radio buttons instead of checkbox
Browse files- src/app.py +11 -9
src/app.py
CHANGED
|
@@ -46,8 +46,8 @@ def format_explanation(pinyin_text: str, translation: str, meaning: str) -> str:
|
|
| 46 |
# Mock function for UI testing
|
| 47 |
# ======================
|
| 48 |
|
| 49 |
-
def find_idiom_mock(
|
| 50 |
-
idiom = "
|
| 51 |
pinyin_text = "duì zhèng xià yào"
|
| 52 |
translation = "To prescribe the right medicine; to take the right approach to a problem."
|
| 53 |
meaning = "add a meaning for the mock"
|
|
@@ -126,13 +126,13 @@ Answer:"""
|
|
| 126 |
# ======================
|
| 127 |
# UI Wrapper
|
| 128 |
# ======================
|
| 129 |
-
def update_ui(situation,
|
| 130 |
if USE_MOCK:
|
| 131 |
-
idiom, explanation = find_idiom_mock(
|
| 132 |
else:
|
| 133 |
idiom, explanation = find_idiom(situation)
|
| 134 |
|
| 135 |
-
idiom_output = char_converter.convert(idiom.split("<br>")[0]) if
|
| 136 |
|
| 137 |
return (
|
| 138 |
f"<div class='idiom-output'>{idiom_output}</div>",
|
|
@@ -156,6 +156,7 @@ def launch_app():
|
|
| 156 |
)
|
| 157 |
generate_btn = gr.Button("✨ Find Idiom")
|
| 158 |
|
|
|
|
| 159 |
# ✅ Example situations
|
| 160 |
gr.Examples(
|
| 161 |
examples=[
|
|
@@ -169,10 +170,11 @@ def launch_app():
|
|
| 169 |
)
|
| 170 |
|
| 171 |
with gr.Column():
|
| 172 |
-
char_mode = gr.
|
| 173 |
-
|
| 174 |
-
value=
|
| 175 |
-
|
|
|
|
| 176 |
)
|
| 177 |
idiom_output = gr.HTML(label="Idiom")
|
| 178 |
explanation_output = gr.HTML(label="Explanation")
|
|
|
|
| 46 |
# Mock function for UI testing
|
| 47 |
# ======================
|
| 48 |
|
| 49 |
+
def find_idiom_mock():
|
| 50 |
+
idiom = "对症下药"
|
| 51 |
pinyin_text = "duì zhèng xià yào"
|
| 52 |
translation = "To prescribe the right medicine; to take the right approach to a problem."
|
| 53 |
meaning = "add a meaning for the mock"
|
|
|
|
| 126 |
# ======================
|
| 127 |
# UI Wrapper
|
| 128 |
# ======================
|
| 129 |
+
def update_ui(situation, char_mode: bool):
|
| 130 |
if USE_MOCK:
|
| 131 |
+
idiom, explanation = find_idiom_mock()
|
| 132 |
else:
|
| 133 |
idiom, explanation = find_idiom(situation)
|
| 134 |
|
| 135 |
+
idiom_output = char_converter.convert(idiom.split("<br>")[0]) if char_mode else idiom
|
| 136 |
|
| 137 |
return (
|
| 138 |
f"<div class='idiom-output'>{idiom_output}</div>",
|
|
|
|
| 156 |
)
|
| 157 |
generate_btn = gr.Button("✨ Find Idiom")
|
| 158 |
|
| 159 |
+
|
| 160 |
# ✅ Example situations
|
| 161 |
gr.Examples(
|
| 162 |
examples=[
|
|
|
|
| 170 |
)
|
| 171 |
|
| 172 |
with gr.Column():
|
| 173 |
+
char_mode = gr.Radio(
|
| 174 |
+
choices=["Simplified", "Traditional"],
|
| 175 |
+
value="Traditional", # default selection
|
| 176 |
+
label="",
|
| 177 |
+
type="index" # will pass 0 for Simplified, 1 for Traditional
|
| 178 |
)
|
| 179 |
idiom_output = gr.HTML(label="Idiom")
|
| 180 |
explanation_output = gr.HTML(label="Explanation")
|