Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -43,11 +43,20 @@ Please include:
|
|
| 43 |
""",
|
| 44 |
},
|
| 45 |
]
|
| 46 |
-
|
|
|
|
|
|
|
| 47 |
|
| 48 |
def process(word_label, lang_label):
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 49 |
selected_word = next((w for w in word_list if w['text'] in word_label), None)
|
| 50 |
-
language_name = lang_label.split("(")[1].strip()
|
| 51 |
|
| 52 |
if not selected_word:
|
| 53 |
yield "❌ Word not found."
|
|
@@ -70,6 +79,9 @@ def process(word_label, lang_label):
|
|
| 70 |
output += chunk.choices[0].delta.content
|
| 71 |
yield output
|
| 72 |
|
|
|
|
|
|
|
|
|
|
| 73 |
except Exception as e:
|
| 74 |
yield f"❌ Error: {e}"
|
| 75 |
|
|
|
|
| 43 |
""",
|
| 44 |
},
|
| 45 |
]
|
| 46 |
+
|
| 47 |
+
# Keep a global/local cache (dict) to store responses
|
| 48 |
+
response_cache = {}
|
| 49 |
|
| 50 |
def process(word_label, lang_label):
|
| 51 |
+
cache_key = (word_label, lang_label)
|
| 52 |
+
|
| 53 |
+
# ✅ Return cached response directly if exists
|
| 54 |
+
if cache_key in response_cache:
|
| 55 |
+
yield response_cache[cache_key]
|
| 56 |
+
return
|
| 57 |
+
|
| 58 |
selected_word = next((w for w in word_list if w['text'] in word_label), None)
|
| 59 |
+
language_name = lang_label.split("(")[1].strip() if "(" in lang_label else lang_label.strip()
|
| 60 |
|
| 61 |
if not selected_word:
|
| 62 |
yield "❌ Word not found."
|
|
|
|
| 79 |
output += chunk.choices[0].delta.content
|
| 80 |
yield output
|
| 81 |
|
| 82 |
+
# ✅ Store the final output in cache
|
| 83 |
+
response_cache[cache_key] = output
|
| 84 |
+
|
| 85 |
except Exception as e:
|
| 86 |
yield f"❌ Error: {e}"
|
| 87 |
|