Update app.py
Browse files37 unmodified lines383940414243444546474849505 unmodified lines565758525960616234 unmodified lines979899931001011021039 unmodified lines11311411511611711810911912012111212212312412512612712812913013113213312213412412512613513613711 unmodified lines14915015115215315415515615715812 unmodified lines17117217317417517617717817918037 unmodified lines url ], text=True).strip()
uploader = subprocess.check_output([ "yt-dlp", "--skip-download", "--print", "%(uploader)s", url ], text=True).strip()
command = [ "yt-dlp", "-x", "--audio-format", "mp3",5 unmodified lines if not os.path.exists(temp_filename): raise Exception("Audio file was not created.")
return temp_filename, description, thumbnail return temp_filename, description, thumbnail, uploader except Exception as e: raise Exception(f"Failed to download video: {e}")
34 unmodified lines thumbnail = None
try: temp_path, description, thumbnail = download_video_audio_and_metadata(audio_url) temp_path, description, thumbnail, author = download_video_audio_and_metadata(audio_url) except Exception: if audio_url.endswith(".mp3"): response = requests.get(audio_url)9 unmodified lines result = model.transcribe(temp_path) os.remove(temp_path)
if description: text_to_process = f"Description:\n{description}\n\nTranscription:\n{result['text']}" else: text_to_process = description if description else result["text"] text_to_process = result["text"]
prompt = f"""You are a professional cooking assistant AI. You are given a transcription or description of a recipe video.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}", "video_description": "Full transcription or description from the video", "description": "A short summary of the recipe (max 2 lines) in {language_code}", "author": "Mentioned author or null", "video_url": "{audio_url}", "thumbnail_url": "{thumbnail if thumbnail else 'null'}", "duration_minutes": 25, "kcal": 600, "difficulty": "easy", // one of: easy, medium, difficult11 unmodified lines "steps": [ "Step 1 in {language_code}...", "Step 2 in {language_code}..." ], "equipment": [ {{ "name": "oven", "icon": "🔥" }}, {{ "name": "blender", "icon": "🌀" }} ]}}
12 unmodified lines return JSONResponse(status_code=500, content={"error": "Invalid JSON from Gemini", "raw": structured_response})
structured_json["video_transcription"] = result["text"] structured_json["video_description"] = description structured_json["video_url"] = audio_url structured_json["thumbnail_url"] = thumbnail structured_json["author"] = author return structured_json
except Exception as e:app.py+24-8