Spaces:
Paused
Paused
Update app.py
Browse files
app.py
CHANGED
|
@@ -12,6 +12,9 @@ from datetime import datetime
|
|
| 12 |
from pathlib import Path
|
| 13 |
from uuid import uuid4
|
| 14 |
from huggingface_hub import CommitScheduler
|
|
|
|
|
|
|
|
|
|
| 15 |
|
| 16 |
|
| 17 |
# Initialize FastAPI
|
|
@@ -59,35 +62,10 @@ scheduler = CommitScheduler(
|
|
| 59 |
def status():
|
| 60 |
return {"status": "200"}
|
| 61 |
|
| 62 |
-
# @app.put("/add/recipe")
|
| 63 |
-
# async def add_recipe(filename: str, recipe: Recipe):
|
| 64 |
-
# # Define the file path based on the filename query parameter
|
| 65 |
-
# file_path = os.path.join(DATASET_PATH, f"{filename}.json")
|
| 66 |
-
|
| 67 |
-
# # Check if the file already exists
|
| 68 |
-
# if os.path.exists(file_path):
|
| 69 |
-
# raise HTTPException(status_code=400, detail="File already exists")
|
| 70 |
-
|
| 71 |
-
# # Prepare the data to be written in JSON format
|
| 72 |
-
# recipe_data = recipe.dict() # Convert Recipe model to dictionary
|
| 73 |
-
|
| 74 |
-
# # Write the data to the new file
|
| 75 |
-
# try:
|
| 76 |
-
# with open(file_path, "w") as f:
|
| 77 |
-
# json.dump(recipe_data, f, indent=4)
|
| 78 |
-
|
| 79 |
-
# dataset = Dataset.from_json(file_path) # Load the new file
|
| 80 |
-
# dataset.push_to_hub("sharktide/recipes") # Push the dataset to the Hugging Face Hub
|
| 81 |
-
|
| 82 |
-
# return {"message": f"Recipe '{filename}' added successfully."}
|
| 83 |
-
# except Exception as e:
|
| 84 |
-
# raise HTTPException(status_code=500, detail=f"Error writing file: {str(e)}")
|
| 85 |
|
| 86 |
-
@app.put("/add/
|
| 87 |
def save_json(filename: str, recipe: Recipe):
|
| 88 |
-
# Save the data to the JSON file
|
| 89 |
with JSON_DATASET_PATH.open("a") as f:
|
| 90 |
-
# Writing the recipe details (name, ingredients, instructions) to the JSON file
|
| 91 |
json.dump({
|
| 92 |
"name": recipe.name,
|
| 93 |
"ingredients": recipe.ingredients,
|
|
@@ -98,4 +76,3 @@ def save_json(filename: str, recipe: Recipe):
|
|
| 98 |
|
| 99 |
|
| 100 |
|
| 101 |
-
# Commit and push the changes to the dataset
|
|
|
|
| 12 |
from pathlib import Path
|
| 13 |
from uuid import uuid4
|
| 14 |
from huggingface_hub import CommitScheduler
|
| 15 |
+
from huggingface_hub import logging
|
| 16 |
+
|
| 17 |
+
logging.set_verbosity_debug()
|
| 18 |
|
| 19 |
|
| 20 |
# Initialize FastAPI
|
|
|
|
| 62 |
def status():
|
| 63 |
return {"status": "200"}
|
| 64 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 65 |
|
| 66 |
+
@app.put("/add/recipe")
|
| 67 |
def save_json(filename: str, recipe: Recipe):
|
|
|
|
| 68 |
with JSON_DATASET_PATH.open("a") as f:
|
|
|
|
| 69 |
json.dump({
|
| 70 |
"name": recipe.name,
|
| 71 |
"ingredients": recipe.ingredients,
|
|
|
|
| 76 |
|
| 77 |
|
| 78 |
|
|
|