Mel Seto
commited on
Commit
·
4609451
1
Parent(s):
3d5b80d
rename generate_idiom to find_idiom
Browse files- src/app.py +4 -4
src/app.py
CHANGED
|
@@ -29,7 +29,7 @@ if not USE_MOCK:
|
|
| 29 |
# ======================
|
| 30 |
# Mock function for UI testing
|
| 31 |
# ======================
|
| 32 |
-
def
|
| 33 |
idiom = "对症下药"
|
| 34 |
explanation = """duì zhèng xià yào<br><br>
|
| 35 |
To prescribe the right medicine; to take the right approach to a problem."""
|
|
@@ -44,7 +44,7 @@ def generate_idiom_mock():
|
|
| 44 |
EXAMPLE_CACHE = {}
|
| 45 |
|
| 46 |
|
| 47 |
-
def
|
| 48 |
"""
|
| 49 |
Generate a verified Chinese idiom for a given situation.
|
| 50 |
|
|
@@ -105,9 +105,9 @@ Answer:"""
|
|
| 105 |
# ======================
|
| 106 |
def update_ui(situation):
|
| 107 |
if USE_MOCK:
|
| 108 |
-
idiom, explanation =
|
| 109 |
else:
|
| 110 |
-
idiom, explanation =
|
| 111 |
|
| 112 |
return (
|
| 113 |
f"<div class='idiom-output'>{idiom}</div>",
|
|
|
|
| 29 |
# ======================
|
| 30 |
# Mock function for UI testing
|
| 31 |
# ======================
|
| 32 |
+
def find_idiom_mock():
|
| 33 |
idiom = "对症下药"
|
| 34 |
explanation = """duì zhèng xià yào<br><br>
|
| 35 |
To prescribe the right medicine; to take the right approach to a problem."""
|
|
|
|
| 44 |
EXAMPLE_CACHE = {}
|
| 45 |
|
| 46 |
|
| 47 |
+
def find_idiom(situation: str, max_attempts: int = 3):
|
| 48 |
"""
|
| 49 |
Generate a verified Chinese idiom for a given situation.
|
| 50 |
|
|
|
|
| 105 |
# ======================
|
| 106 |
def update_ui(situation):
|
| 107 |
if USE_MOCK:
|
| 108 |
+
idiom, explanation = find_idiom_mock()
|
| 109 |
else:
|
| 110 |
+
idiom, explanation = find_idiom(situation)
|
| 111 |
|
| 112 |
return (
|
| 113 |
f"<div class='idiom-output'>{idiom}</div>",
|