Spaces:
Sleeping
Sleeping
Nick Starkov
commited on
Commit
·
302c8fe
1
Parent(s):
349b690
Change
Browse files
app.py
CHANGED
|
@@ -2,7 +2,6 @@ import os
|
|
| 2 |
from fastapi import FastAPI
|
| 3 |
from datasets import load_dataset
|
| 4 |
import random
|
| 5 |
-
import json
|
| 6 |
|
| 7 |
# Set Hugging Face cache directory programmatically as a fallback
|
| 8 |
os.environ["HF_HOME"] = "/app/cache"
|
|
@@ -19,15 +18,9 @@ async def get_idioms():
|
|
| 19 |
# Extract required fields
|
| 20 |
response = []
|
| 21 |
for item in idioms:
|
| 22 |
-
# Parse the output field as JSON
|
| 23 |
-
try:
|
| 24 |
-
output_data = json.loads(item.get("output", "{}"))
|
| 25 |
-
compound_type = output_data.get("Compound Type", "").strip('"')
|
| 26 |
-
except json.JSONDecodeError:
|
| 27 |
-
compound_type = ""
|
| 28 |
response.append({
|
| 29 |
"idiom": item.get("compound", ""),
|
| 30 |
"example": item.get("sentence", ""),
|
| 31 |
-
"definition":
|
| 32 |
})
|
| 33 |
return response
|
|
|
|
| 2 |
from fastapi import FastAPI
|
| 3 |
from datasets import load_dataset
|
| 4 |
import random
|
|
|
|
| 5 |
|
| 6 |
# Set Hugging Face cache directory programmatically as a fallback
|
| 7 |
os.environ["HF_HOME"] = "/app/cache"
|
|
|
|
| 18 |
# Extract required fields
|
| 19 |
response = []
|
| 20 |
for item in idioms:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 21 |
response.append({
|
| 22 |
"idiom": item.get("compound", ""),
|
| 23 |
"example": item.get("sentence", ""),
|
| 24 |
+
"definition": item.get("output", ""),
|
| 25 |
})
|
| 26 |
return response
|