Update app.py
Browse files14 unmodified lines15161718192021136 unmodified lines15815916016016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220316116216316416516616716816917014 unmodified lines
os.environ["XDG_CACHE_HOME"] = "/tmp"gemini_api_key = os.environ["GEMINI_API_KEY"]prompt_template = os.environ.get("PROMPT_TEMPLATE")app = FastAPI()model = whisper.load_model("tiny")
136 unmodified lines else: text_to_process = result["text"]
prompt = f"""You are a professional cooking assistant AI. You are given a transcription and a description of a recipe video if available.
Your task is to extract and return ONLY valid JSON in the following format. The content must be written in the following language: **{language_code}**.
If the original text does not mention exact values (duration, kcal, servings, etc.), you must estimate reasonable values based on the ingredients and preparation steps.
You must also infer what kitchen equipment or tools are required to prepare the recipe. Do NOT include basic/common items like knives, spoons, plates, or glasses. Include only special equipment like oven, blender, air fryer, etc.
Respond ONLY with valid JSON like this:
{{ "title": "Translated recipe title in {language_code}", "description": "A short summary of the recipe (max 2 lines) in {language_code}", "duration_minutes": 25, "kcal": 600, "difficulty": "easy", // one of: easy, medium, difficult "servings": 2, "ingredients": {{ "elaboration_title": [ {{ "quantity": 1.5, "unit": "tsp", "name": "translated ingredient name in {language_code}", "icon": "🧂" }} ] }}, "steps": [ "Step 1 in {language_code}...", "Step 2 in {language_code}..." ], "equipment": [ {{ "name": "oven", "icon": "🔥" }}, {{ "name": "blender", "icon": "🌀" }} ]}}
If any field cannot be inferred with reasonable logic, return `null`.
Text to analyze:
\"\"\"{text_to_process}\"\"\"""" if not prompt_template: raise Exception("Missing PROMPT_TEMPLATE environment variable")
prompt = prompt_template.format( language_code=language_code, text_to_process=text_to_process )
structured_response = call_gemini(prompt, gemini_api_key) try:app.py+8-44