Spaces:
Runtime error
Runtime error
update.py
#2
by
sathwik2004
- opened
app.py
CHANGED
|
@@ -1,120 +1,493 @@
|
|
| 1 |
-
import
|
| 2 |
-
import
|
| 3 |
-
import
|
| 4 |
-
|
| 5 |
-
import
|
| 6 |
-
|
| 7 |
-
|
| 8 |
-
import
|
| 9 |
-
|
| 10 |
-
#
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
#
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
|
| 29 |
-
|
| 30 |
-
|
| 31 |
-
|
| 32 |
-
|
| 33 |
-
|
| 34 |
-
|
| 35 |
-
|
| 36 |
-
|
| 37 |
-
|
| 38 |
-
|
| 39 |
-
|
| 40 |
-
|
| 41 |
-
|
| 42 |
-
|
| 43 |
-
|
| 44 |
-
|
| 45 |
-
|
| 46 |
-
|
| 47 |
-
|
| 48 |
-
|
| 49 |
-
|
| 50 |
-
|
| 51 |
-
|
| 52 |
-
|
| 53 |
-
|
| 54 |
-
|
| 55 |
-
|
| 56 |
-
|
| 57 |
-
|
| 58 |
-
|
| 59 |
-
|
| 60 |
-
|
| 61 |
-
|
| 62 |
-
|
| 63 |
-
|
| 64 |
-
|
| 65 |
-
|
| 66 |
-
|
| 67 |
-
|
| 68 |
-
|
| 69 |
-
|
| 70 |
-
|
| 71 |
-
|
| 72 |
-
|
| 73 |
-
|
| 74 |
-
|
| 75 |
-
|
| 76 |
-
|
| 77 |
-
|
| 78 |
-
|
| 79 |
-
|
| 80 |
-
|
| 81 |
-
|
| 82 |
-
|
| 83 |
-
|
| 84 |
-
|
| 85 |
-
|
| 86 |
-
|
| 87 |
-
|
| 88 |
-
|
| 89 |
-
|
| 90 |
-
|
| 91 |
-
|
| 92 |
-
|
| 93 |
-
|
| 94 |
-
|
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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
import pandas as pd
|
| 3 |
+
import os
|
| 4 |
+
import requests
|
| 5 |
+
import json
|
| 6 |
+
from collections import defaultdict
|
| 7 |
+
import re
|
| 8 |
+
import urllib.parse
|
| 9 |
+
|
| 10 |
+
# Load the dataset
|
| 11 |
+
df = pd.read_csv("recipes_dataset.csv")
|
| 12 |
+
|
| 13 |
+
# Bria API Configuration
|
| 14 |
+
BRIA_API_KEY = os.getenv("BRIA_API_KEY", "3e0c700582c74fa58bb5c219b458da66") # Set your Bria API key as environment variable
|
| 15 |
+
BRIA_API_URL = "https://api.bria.ai/v1/text-to-image"
|
| 16 |
+
|
| 17 |
+
# Language translations dictionary
|
| 18 |
+
TRANSLATIONS = {
|
| 19 |
+
'English': {
|
| 20 |
+
'app_title': '🍳 Telugu Recipe App with AI Images',
|
| 21 |
+
'app_subtitle': 'Search for delicious Telugu recipes with AI-generated images and video tutorials!',
|
| 22 |
+
'search_recipe': 'Search Recipe',
|
| 23 |
+
'enter_recipe_name': 'Enter Recipe Name',
|
| 24 |
+
'recipe_placeholder': 'e.g., Chicken Curry, Fish Curry, Biryani...',
|
| 25 |
+
'search_button': '🔍 Search Recipe with Images',
|
| 26 |
+
'all_recipes': 'All Recipes',
|
| 27 |
+
'show_all_recipes': '📋 Show All Recipes',
|
| 28 |
+
'quick_recipes': 'Quick Recipes',
|
| 29 |
+
'maximum_time': 'Maximum Time (minutes)',
|
| 30 |
+
'find_quick_recipes': '⚡ Find Quick Recipes',
|
| 31 |
+
'categories': 'Categories',
|
| 32 |
+
'show_categories': '📊 Show Recipe Categories',
|
| 33 |
+
'cooking_time': 'Cooking Time',
|
| 34 |
+
'ingredients': 'Ingredients',
|
| 35 |
+
'no_recipe_found': 'No recipe found for',
|
| 36 |
+
'please_enter_recipe': 'Please enter a recipe name!',
|
| 37 |
+
'available_recipes': 'Available Recipes',
|
| 38 |
+
'recipes_under_time': 'Recipes under',
|
| 39 |
+
'minutes': 'minutes',
|
| 40 |
+
'no_recipes_under_time': 'No recipes found under',
|
| 41 |
+
'recipe_categories': 'Recipe Categories',
|
| 42 |
+
'curry_dishes': 'Curry Dishes',
|
| 43 |
+
'rice_dishes': 'Rice Dishes',
|
| 44 |
+
'egg_dishes': 'Egg Dishes',
|
| 45 |
+
'please_enter_valid_time': 'Please enter a valid time!',
|
| 46 |
+
'convert_to': 'Convert to',
|
| 47 |
+
'language_options': ['Telugu', 'Tamil', 'Hindi'],
|
| 48 |
+
'generated_image': 'AI Generated Recipe Image',
|
| 49 |
+
'video_tutorials': 'Recommended Video Tutorials',
|
| 50 |
+
'image_generation_failed': 'Failed to generate image',
|
| 51 |
+
'api_key_missing': 'Bria API key not configured',
|
| 52 |
+
'generating_image': 'Generating AI image...',
|
| 53 |
+
'searching_videos': 'Finding video tutorials...',
|
| 54 |
+
'visual_guide': 'Visual Guide & Tutorials'
|
| 55 |
+
},
|
| 56 |
+
'Telugu': {
|
| 57 |
+
'app_title': '🍳 తెలుగు వంటల యాప్ AI చిత్రాలతో',
|
| 58 |
+
'app_subtitle': 'AI చిత్రాలు మరియు వీడియో ట్యుటోరియల్స్తో రుచికరమైన తెలుగు వంటకాల కోసం వెతకండి!',
|
| 59 |
+
'search_recipe': 'వంటకం వెతుకు',
|
| 60 |
+
'enter_recipe_name': 'వంటకం పేరు ఎంటర్ చేయండి',
|
| 61 |
+
'recipe_placeholder': 'ఉదా., చికెన్ కూర, ఫిష్ కూర, బిర్యానీ...',
|
| 62 |
+
'search_button': '🔍 చిత్రాలతో వంటకం వెతుకు',
|
| 63 |
+
'all_recipes': 'అన్ని వంటకాలు',
|
| 64 |
+
'show_all_recipes': '📋 అన్ని వంటకాలు చూపించు',
|
| 65 |
+
'quick_recipes': 'త్వరగా చేసే వంటకాలు',
|
| 66 |
+
'maximum_time': 'గరిష్ట సమయం (నిమిషాలు)',
|
| 67 |
+
'find_quick_recipes': '⚡ త్వరగా చేసే వంటకాలు కనుగొనండి',
|
| 68 |
+
'categories': 'వర్గాలు',
|
| 69 |
+
'show_categories': '📊 వంటకాల వర్గాలు చూపించు',
|
| 70 |
+
'cooking_time': 'వంట సమయం',
|
| 71 |
+
'ingredients': 'పదార్థాలు',
|
| 72 |
+
'no_recipe_found': 'దొరకలేదు',
|
| 73 |
+
'please_enter_recipe': 'దయచేసి వంటకం పేరు ఎంటర్ చేయండి!',
|
| 74 |
+
'available_recipes': 'అందుబాటులో ఉన్న వంటకాలు',
|
| 75 |
+
'recipes_under_time': 'వంటకాలు',
|
| 76 |
+
'minutes': 'నిమిషాలలోపు',
|
| 77 |
+
'no_recipes_under_time': 'నిమిషాలలోపు వంటకాలు లేవు',
|
| 78 |
+
'recipe_categories': 'వంటకాల వర్గాలు',
|
| 79 |
+
'curry_dishes': 'కూర వంటకాలు',
|
| 80 |
+
'rice_dishes': 'అన్నం వంటకాలు',
|
| 81 |
+
'egg_dishes': 'గుడ్డు వంటకాలు',
|
| 82 |
+
'please_enter_valid_time': 'దయచేసి సరైన సమయం ఎంటర్ చేయండి!',
|
| 83 |
+
'convert_to': 'మార్చు',
|
| 84 |
+
'language_options': ['English', 'Tamil', 'Hindi'],
|
| 85 |
+
'generated_image': 'AI రూపొందించిన వంటకం చిత్రం',
|
| 86 |
+
'video_tutorials': 'సిఫార్సు చేయబడిన వీడియో ట్యుటోరియల్స్',
|
| 87 |
+
'image_generation_failed': 'చిత్రం రూపొందించడంలో విఫలమైంది',
|
| 88 |
+
'api_key_missing': 'Bria API కీ కాన్ఫిగర్ చేయబడలేదు',
|
| 89 |
+
'generating_image': 'AI చిత్రం రూపొందిస్తోంది...',
|
| 90 |
+
'searching_videos': 'వీడియో ట్యుటోరియల్స్ వెతుకుతోంది...',
|
| 91 |
+
'visual_guide': 'దృశ్య గైడ్ & ట్యుటోరియల్స్'
|
| 92 |
+
},
|
| 93 |
+
'Tamil': {
|
| 94 |
+
'app_title': '🍳 தெலுங்கு சமையல் பயன்பாடு AI படங்களுடன்',
|
| 95 |
+
'app_subtitle': 'AI படங்கள் மற்றும் வீடியோ டுடோரியல்களுடன் சுவையான தெலுங்கு சமையல் குறிப்புகளை தேடுங்கள்!',
|
| 96 |
+
'search_recipe': 'சமையல் தேடுக',
|
| 97 |
+
'enter_recipe_name': 'சமையல் பெயர் உள்ளிடவும்',
|
| 98 |
+
'recipe_placeholder': 'எ.கா., சிக்கன் கறி, மீன் கறி, பிரியாணி...',
|
| 99 |
+
'search_button': '🔍 படங்களுடன் சமையல் தேடுக',
|
| 100 |
+
'all_recipes': 'அனைத்து சமையல்',
|
| 101 |
+
'show_all_recipes': '📋 அனைத்து சமையல் காட்டுக',
|
| 102 |
+
'quick_recipes': 'விரைவு சமையல்',
|
| 103 |
+
'maximum_time': 'அதிகபட்ச நேரம் (நிமிடங்கள்)',
|
| 104 |
+
'find_quick_recipes': '⚡ விரைவு சமையல் கண்டுபிடிக்கவும்',
|
| 105 |
+
'categories': 'வகைகள்',
|
| 106 |
+
'show_categories': '📊 சமையல் வகைகள் காட்டுக',
|
| 107 |
+
'cooking_time': 'சமையல் நேரம்',
|
| 108 |
+
'ingredients': 'பொருட்கள்',
|
| 109 |
+
'no_recipe_found': 'கண்டுபிடிக்க முடியவில்லை',
|
| 110 |
+
'please_enter_recipe': 'தயவுசெய்து சமையல் பெயர் உள்ளிடவும்!',
|
| 111 |
+
'available_recipes': 'கிடைக்கும் சமையல்',
|
| 112 |
+
'recipes_under_time': 'சமையல்',
|
| 113 |
+
'minutes': 'நிமிடங்களுக்குள்',
|
| 114 |
+
'no_recipes_under_time': 'நிமிடங்களுக்குள் சமையல் இல்லை',
|
| 115 |
+
'recipe_categories': 'சமையல் வகைகள்',
|
| 116 |
+
'curry_dishes': 'கறி வகைகள்',
|
| 117 |
+
'rice_dishes': 'சாதம் வகைகள்',
|
| 118 |
+
'egg_dishes': 'முட்டை வகைகள்',
|
| 119 |
+
'please_enter_valid_time': 'தயவுசெய்து சரியான நேரம் உள்ளிடவும்!',
|
| 120 |
+
'convert_to': 'மாற்று',
|
| 121 |
+
'language_options': ['English', 'Telugu', 'Hindi'],
|
| 122 |
+
'generated_image': 'AI உருவாக்கிய சமையல் படம்',
|
| 123 |
+
'video_tutorials': 'பரிந்துரைக்கப்பட்ட வீடியோ டுடோரியல்கள்',
|
| 124 |
+
'image_generation_failed': 'படம் உருவாக்குவதில் தோல்வி',
|
| 125 |
+
'api_key_missing': 'Bria API கீ கட்டமைக்கப்படவில்லை',
|
| 126 |
+
'generating_image': 'AI படம் உருவாக்குகிறது...',
|
| 127 |
+
'searching_videos': 'வீடியோ டுடோரியல்களை தேடுகிறது...',
|
| 128 |
+
'visual_guide': 'காட்சி வழிகாட்டி & டுடோரியல்கள்'
|
| 129 |
+
},
|
| 130 |
+
'Hindi': {
|
| 131 |
+
'app_title': '🍳 तेलुगु रेसिपी ऐप AI चित्रों के साथ',
|
| 132 |
+
'app_subtitle': 'AI चित्रों और वीडियो ट्यूटोरियल के साथ स्वादिष्ट तेलुगु व्यंजनों की खोज करें!',
|
| 133 |
+
'search_recipe': 'रेसिपी खोजें',
|
| 134 |
+
'enter_recipe_name': 'रेसिपी का नाम दर्ज करें',
|
| 135 |
+
'recipe_placeholder': 'जैसे, चिकन करी, फिश करी, बिरयानी...',
|
| 136 |
+
'search_button': '🔍 चित्रों के साथ रेसिपी खोजें',
|
| 137 |
+
'all_recipes': 'सभी रेसिपी',
|
| 138 |
+
'show_all_recipes': '📋 सभी रेसिपी दिखाएं',
|
| 139 |
+
'quick_recipes': 'त्वरित रेसिपी',
|
| 140 |
+
'maximum_time': 'अधिकतम समय (मिनट)',
|
| 141 |
+
'find_quick_recipes': '⚡ त्वरित रेसिपी खोजें',
|
| 142 |
+
'categories': 'श्रेणियां',
|
| 143 |
+
'show_categories': '📊 रेसिपी श्रेणियां दिखाएं',
|
| 144 |
+
'cooking_time': 'खाना पकाने का समय',
|
| 145 |
+
'ingredients': 'सामग्री',
|
| 146 |
+
'no_recipe_found': 'नहीं मिली',
|
| 147 |
+
'please_enter_recipe': 'कृपया रेसिपी का नाम दर्ज करें!',
|
| 148 |
+
'available_recipes': 'उपलब्ध रेसिपी',
|
| 149 |
+
'recipes_under_time': 'रेसिपी',
|
| 150 |
+
'minutes': 'मिनट के अंदर',
|
| 151 |
+
'no_recipes_under_time': 'मिनट के अंदर कोई रेसिपी नहीं मिली',
|
| 152 |
+
'recipe_categories': 'रेसिपी श्रेणियां',
|
| 153 |
+
'curry_dishes': 'करी व्यंजन',
|
| 154 |
+
'rice_dishes': 'चावल व्यंजन',
|
| 155 |
+
'egg_dishes': 'अंडे के व्यंजन',
|
| 156 |
+
'please_enter_valid_time': 'कृपया वैध समय दर्ज करें!',
|
| 157 |
+
'convert_to': 'में बदलें',
|
| 158 |
+
'language_options': ['English', 'Telugu', 'Tamil'],
|
| 159 |
+
'generated_image': 'AI द्वारा बनाई गई रेसिपी तस्वीर',
|
| 160 |
+
'video_tutorials': 'सुझाए गए वीडियो ट्यूटोरियल',
|
| 161 |
+
'image_generation_failed': 'छवि बनाने में विफल',
|
| 162 |
+
'api_key_missing': 'Bria API कुंजी कॉन्फ़िगर नहीं है',
|
| 163 |
+
'generating_image': 'AI छवि बना रहा है...',
|
| 164 |
+
'searching_videos': 'वीडियो ट्यूटोरियल खोज रहा है...',
|
| 165 |
+
'visual_guide': 'दृश्य गाइड और ट्यूटोरियल'
|
| 166 |
+
}
|
| 167 |
+
}
|
| 168 |
+
|
| 169 |
+
def process_recipe_data():
|
| 170 |
+
"""Process the CSV data to group ingredients by recipe"""
|
| 171 |
+
recipes = defaultdict(lambda: {
|
| 172 |
+
'english_name': '',
|
| 173 |
+
'telugu_name': '',
|
| 174 |
+
'cooking_time_english': '',
|
| 175 |
+
'cooking_time_telugu': '',
|
| 176 |
+
'ingredients_english': [],
|
| 177 |
+
'ingredients_telugu': []
|
| 178 |
+
})
|
| 179 |
+
|
| 180 |
+
for _, row in df.iterrows():
|
| 181 |
+
recipe_name = row['English Name']
|
| 182 |
+
recipes[recipe_name]['english_name'] = row['English Name']
|
| 183 |
+
recipes[recipe_name]['telugu_name'] = row['Telugu Name']
|
| 184 |
+
recipes[recipe_name]['cooking_time_english'] = row['Cooking Time (English)']
|
| 185 |
+
recipes[recipe_name]['cooking_time_telugu'] = row['Cooking Time (Telugu)']
|
| 186 |
+
recipes[recipe_name]['ingredients_english'].append(row['Ingredient (English)'])
|
| 187 |
+
recipes[recipe_name]['ingredients_telugu'].append(row['Ingredient (Telugu)'])
|
| 188 |
+
|
| 189 |
+
return dict(recipes)
|
| 190 |
+
|
| 191 |
+
# Process the data
|
| 192 |
+
recipes_data = process_recipe_data()
|
| 193 |
+
|
| 194 |
+
def get_translation(key, language='English'):
|
| 195 |
+
"""Get translation for a given key and language"""
|
| 196 |
+
return TRANSLATIONS.get(language, TRANSLATIONS['English']).get(key, key)
|
| 197 |
+
|
| 198 |
+
def generate_recipe_image(recipe_name, ingredients_list):
|
| 199 |
+
"""Generate realistic recipe image using Bria API"""
|
| 200 |
+
if not BRIA_API_KEY:
|
| 201 |
+
return None, "API key not configured"
|
| 202 |
+
|
| 203 |
+
try:
|
| 204 |
+
# Create detailed prompt for realistic food photography
|
| 205 |
+
main_ingredients = ", ".join(ingredients_list[:5]) # Use first 5 ingredients
|
| 206 |
+
|
| 207 |
+
prompt = f"""Professional food photography of {recipe_name}, beautifully plated authentic Indian Telugu cuisine,
|
| 208 |
+
featuring {main_ingredients}, vibrant colors, traditional serving dish,
|
| 209 |
+
restaurant quality presentation, natural lighting, appetizing appearance,
|
| 210 |
+
high resolution, detailed textures, garnished appropriately,
|
| 211 |
+
traditional Indian food styling, warm ambient lighting"""
|
| 212 |
+
|
| 213 |
+
headers = {
|
| 214 |
+
"Authorization": f"Bearer {BRIA_API_KEY}",
|
| 215 |
+
"Content-Type": "application/json"
|
| 216 |
+
}
|
| 217 |
+
|
| 218 |
+
data = {
|
| 219 |
+
"prompt": prompt,
|
| 220 |
+
"num_results": 1,
|
| 221 |
+
"width": 512,
|
| 222 |
+
"height": 512,
|
| 223 |
+
"style_type": "photography",
|
| 224 |
+
"enhancement": True
|
| 225 |
+
}
|
| 226 |
+
|
| 227 |
+
response = requests.post(BRIA_API_URL, headers=headers, json=data, timeout=30)
|
| 228 |
+
|
| 229 |
+
if response.status_code == 200:
|
| 230 |
+
result = response.json()
|
| 231 |
+
if 'results' in result and len(result['results']) > 0:
|
| 232 |
+
return result['results'][0]['url'], None
|
| 233 |
+
else:
|
| 234 |
+
return None, "No image generated"
|
| 235 |
+
else:
|
| 236 |
+
return None, f"API Error: {response.status_code}"
|
| 237 |
+
|
| 238 |
+
except requests.exceptions.Timeout:
|
| 239 |
+
return None, "Request timeout"
|
| 240 |
+
except Exception as e:
|
| 241 |
+
return None, f"Error: {str(e)}"
|
| 242 |
+
|
| 243 |
+
def generate_youtube_links(recipe_name, telugu_name=""):
|
| 244 |
+
"""Generate relevant YouTube tutorial links for the recipe"""
|
| 245 |
+
search_queries = []
|
| 246 |
+
|
| 247 |
+
# Create multiple search variations for better results
|
| 248 |
+
base_recipe = recipe_name.replace(" ", "+")
|
| 249 |
+
search_queries.append(f"{base_recipe}+recipe+telugu")
|
| 250 |
+
search_queries.append(f"{base_recipe}+cooking+tutorial")
|
| 251 |
+
search_queries.append(f"how+to+make+{base_recipe}")
|
| 252 |
+
|
| 253 |
+
if telugu_name:
|
| 254 |
+
telugu_encoded = urllib.parse.quote(telugu_name)
|
| 255 |
+
search_queries.append(f"{telugu_encoded}+recipe")
|
| 256 |
+
|
| 257 |
+
# Add specific cooking channel searches
|
| 258 |
+
popular_channels = [
|
| 259 |
+
"Hebbars+Kitchen", "Vahrehvah", "Cook+with+Comali",
|
| 260 |
+
"Telugu+Cooking", "Andhra+Recipes", "South+Indian+Recipes"
|
| 261 |
+
]
|
| 262 |
+
|
| 263 |
+
video_links = []
|
| 264 |
+
|
| 265 |
+
for i, query in enumerate(search_queries[:3]): # Limit to 3 main searches
|
| 266 |
+
youtube_url = f"https://www.youtube.com/results?search_query={query}"
|
| 267 |
+
|
| 268 |
+
# Create more specific search URLs
|
| 269 |
+
video_links.append({
|
| 270 |
+
"title": f"🎥 {recipe_name} - Recipe Tutorial",
|
| 271 |
+
"url": youtube_url,
|
| 272 |
+
"description": f"Complete cooking tutorial for {recipe_name}"
|
| 273 |
+
})
|
| 274 |
+
|
| 275 |
+
# Add channel-specific searches
|
| 276 |
+
for channel in popular_channels[:2]:
|
| 277 |
+
channel_search = f"https://www.youtube.com/results?search_query={base_recipe}+{channel}"
|
| 278 |
+
video_links.append({
|
| 279 |
+
"title": f"🍳 {recipe_name} by {channel.replace('+', ' ')}",
|
| 280 |
+
"url": channel_search,
|
| 281 |
+
"description": f"Professional cooking tutorial from {channel.replace('+', ' ')}"
|
| 282 |
+
})
|
| 283 |
+
|
| 284 |
+
# Add general cooking tips search
|
| 285 |
+
tips_search = f"https://www.youtube.com/results?search_query={base_recipe}+tips+tricks+secrets"
|
| 286 |
+
video_links.append({
|
| 287 |
+
"title": f"💡 {recipe_name} - Tips & Secrets",
|
| 288 |
+
"url": tips_search,
|
| 289 |
+
"description": f"Professional cooking tips and secrets for perfect {recipe_name}"
|
| 290 |
+
})
|
| 291 |
+
|
| 292 |
+
return video_links
|
| 293 |
+
|
| 294 |
+
def format_video_links(video_links, current_language="English"):
|
| 295 |
+
"""Format video links for display"""
|
| 296 |
+
if not video_links:
|
| 297 |
+
return f"**{get_translation('video_tutorials', current_language)}:** No tutorials found"
|
| 298 |
+
|
| 299 |
+
formatted_links = f"**🎬 {get_translation('video_tutorials', current_language)}:**\n\n"
|
| 300 |
+
|
| 301 |
+
for i, video in enumerate(video_links, 1):
|
| 302 |
+
formatted_links += f"**{i}. [{video['title']}]({video['url']})**\n"
|
| 303 |
+
formatted_links += f" *{video['description']}*\n\n"
|
| 304 |
+
|
| 305 |
+
# Add helpful note
|
| 306 |
+
if current_language == "English":
|
| 307 |
+
formatted_links += "💡 **Note:** Click on any link above to search for detailed video tutorials on YouTube.\n"
|
| 308 |
+
formatted_links += "🔍 **Tip:** Use Telugu keywords in YouTube search for more authentic regional recipes."
|
| 309 |
+
elif current_language == "Telugu":
|
| 310 |
+
formatted_links += "💡 **గమనిక:** వివరణాత్మక వీడియో ట్యుటోరియల్స్ కోసం యూట్యూబ్లో వెతకడానికి ఎగువన ఉన్న ఏదైనా లింక్ను క్లిక్ చేయండి.\n"
|
| 311 |
+
formatted_links += "🔍 **చిట్కా:** మరింత అసలైన ప్రాంతీయ వంటకాల కోసం యూట్యూబ్ వెతుకులలో తెలుగు పదాలను ఉపయోగించండి."
|
| 312 |
+
|
| 313 |
+
return formatted_links
|
| 314 |
+
|
| 315 |
+
def assess_recipe_complexity(recipe_name, ingredients_list, cooking_time):
|
| 316 |
+
"""Assess if recipe needs video explanation based on complexity"""
|
| 317 |
+
complexity_score = 0
|
| 318 |
+
|
| 319 |
+
# Check for complex ingredients
|
| 320 |
+
complex_ingredients = ['paste', 'marinade', 'tempering', 'tadka', 'masala', 'curry leaves', 'ghee']
|
| 321 |
+
for ingredient in ingredients_list:
|
| 322 |
+
if any(complex_word in ingredient.lower() for complex_word in complex_ingredients):
|
| 323 |
+
complexity_score += 1
|
| 324 |
+
|
| 325 |
+
# Check cooking time
|
| 326 |
+
time_str = cooking_time.lower()
|
| 327 |
+
if 'hour' in time_str or 'hours' in time_str:
|
| 328 |
+
complexity_score += 2
|
| 329 |
+
elif any(num in time_str for num in ['45', '50', '60']) and 'minute' in time_str:
|
| 330 |
+
complexity_score += 1
|
| 331 |
+
|
| 332 |
+
# Check for complex cooking methods
|
| 333 |
+
complex_methods = ['biryani', 'curry', 'fry', 'roast', 'pickle', 'chutney']
|
| 334 |
+
if any(method in recipe_name.lower() for method in complex_methods):
|
| 335 |
+
complexity_score += 1
|
| 336 |
+
|
| 337 |
+
return complexity_score >= 2 # Recommend videos if complexity score is 2 or higher
|
| 338 |
+
|
| 339 |
+
def search_recipe(recipe_name, current_language="English"):
|
| 340 |
+
"""Search for a recipe and return details with AI image and video links"""
|
| 341 |
+
if not recipe_name.strip():
|
| 342 |
+
return get_translation('please_enter_recipe', current_language), "", "", "", None, ""
|
| 343 |
+
|
| 344 |
+
found_recipe = None
|
| 345 |
+
for recipe_key, recipe_info in recipes_data.items():
|
| 346 |
+
if (recipe_name.lower() in recipe_info['english_name'].lower() or
|
| 347 |
+
recipe_name in recipe_info['telugu_name'] or
|
| 348 |
+
recipe_name.lower() in recipe_key.lower()):
|
| 349 |
+
found_recipe = recipe_info
|
| 350 |
+
break
|
| 351 |
+
|
| 352 |
+
if not found_recipe:
|
| 353 |
+
return f"❌ {get_translation('no_recipe_found', current_language)} '{recipe_name}'", "", "", "", None, ""
|
| 354 |
+
|
| 355 |
+
# Basic recipe information
|
| 356 |
+
title = f"🍳 {found_recipe['english_name']}"
|
| 357 |
+
if current_language != 'English' and found_recipe['telugu_name']:
|
| 358 |
+
title += f" ({found_recipe['telugu_name']})"
|
| 359 |
+
|
| 360 |
+
time_info = f"⏰ **{get_translation('cooking_time', current_language)}:** {found_recipe['cooking_time_english']}"
|
| 361 |
+
|
| 362 |
+
ingredients_list = f"📋 **{get_translation('ingredients', current_language)}:**\n"
|
| 363 |
+
for i, ingredient in enumerate(found_recipe['ingredients_english'], 1):
|
| 364 |
+
ingredients_list += f"{i}. {ingredient}\n"
|
| 365 |
+
|
| 366 |
+
# Bilingual ingredients
|
| 367 |
+
bilingual_ingredients = f"📋 **{get_translation('ingredients', current_language)} (English + తెలుగు):**\n\n"
|
| 368 |
+
for i, (eng, tel) in enumerate(zip(found_recipe['ingredients_english'], found_recipe['ingredients_telugu']), 1):
|
| 369 |
+
bilingual_ingredients += f"{i}. **English:** {eng}\n **తెల���గు:** {tel}\n\n"
|
| 370 |
+
|
| 371 |
+
# Generate AI image
|
| 372 |
+
image_url = None
|
| 373 |
+
image_status = get_translation('generating_image', current_language)
|
| 374 |
+
|
| 375 |
+
try:
|
| 376 |
+
if BRIA_API_KEY:
|
| 377 |
+
image_url, error = generate_recipe_image(found_recipe['english_name'], found_recipe['ingredients_english'])
|
| 378 |
+
if error:
|
| 379 |
+
image_status = f"❌ {get_translation('image_generation_failed', current_language)}: {error}"
|
| 380 |
+
else:
|
| 381 |
+
image_status = f"✅ {get_translation('generated_image', current_language)}"
|
| 382 |
+
else:
|
| 383 |
+
image_status = f"⚠️ {get_translation('api_key_missing', current_language)}"
|
| 384 |
+
except Exception as e:
|
| 385 |
+
image_status = f"❌ {get_translation('image_generation_failed', current_language)}: {str(e)}"
|
| 386 |
+
|
| 387 |
+
# Generate YouTube video links
|
| 388 |
+
video_links = generate_youtube_links(found_recipe['english_name'], found_recipe['telugu_name'])
|
| 389 |
+
formatted_videos = format_video_links(video_links, current_language)
|
| 390 |
+
|
| 391 |
+
# Add complexity assessment
|
| 392 |
+
needs_video = assess_recipe_complexity(
|
| 393 |
+
found_recipe['english_name'],
|
| 394 |
+
found_recipe['ingredients_english'],
|
| 395 |
+
found_recipe['cooking_time_english']
|
| 396 |
+
)
|
| 397 |
+
|
| 398 |
+
if needs_video:
|
| 399 |
+
if current_language == "English":
|
| 400 |
+
formatted_videos = "🎯 **This recipe involves complex techniques - Video tutorials highly recommended!**\n\n" + formatted_videos
|
| 401 |
+
elif current_language == "Telugu":
|
| 402 |
+
formatted_videos = "🎯 **ఈ వంటకంలో సంక్లిష్ట పద్ధతులు ఉన్నాయి - వీడియో ట్యుటోరియల్స్ బాగా సిఫార్సు చేయబడుతున్నాయి!**\n\n" + formatted_videos
|
| 403 |
+
|
| 404 |
+
# Combine image status with video links
|
| 405 |
+
visual_content = f"## 🎬 {get_translation('visual_guide', current_language)}\n\n"
|
| 406 |
+
visual_content += f"**📸 {image_status}**\n\n"
|
| 407 |
+
visual_content += formatted_videos
|
| 408 |
+
|
| 409 |
+
return title, time_info, ingredients_list, bilingual_ingredients, image_url, visual_content
|
| 410 |
+
|
| 411 |
+
def get_all_recipes(current_language="English"):
|
| 412 |
+
"""Get all recipes list in the specified language"""
|
| 413 |
+
recipes_list = f"📚 **{get_translation('available_recipes', current_language)}:**\n\n"
|
| 414 |
+
for i, (recipe_key, recipe_info) in enumerate(recipes_data.items(), 1):
|
| 415 |
+
if current_language == 'English':
|
| 416 |
+
recipes_list += f"{i}. **{recipe_info['english_name']}**\n"
|
| 417 |
+
else:
|
| 418 |
+
recipes_list += f"{i}. **{recipe_info['english_name']}** | **{recipe_info['telugu_name']}**\n"
|
| 419 |
+
return recipes_list
|
| 420 |
+
|
| 421 |
+
def filter_by_time(max_time, current_language="English"):
|
| 422 |
+
"""Filter recipes by cooking time"""
|
| 423 |
+
if max_time <= 0:
|
| 424 |
+
return get_translation('please_enter_valid_time', current_language)
|
| 425 |
+
|
| 426 |
+
quick_recipes = []
|
| 427 |
+
for recipe_key, recipe_info in recipes_data.items():
|
| 428 |
+
time_str = recipe_info['cooking_time_english'].lower()
|
| 429 |
+
if 'hour' in time_str:
|
| 430 |
+
if '1 hour 15' in time_str:
|
| 431 |
+
total_minutes = 75
|
| 432 |
+
elif '1 hour' in time_str:
|
| 433 |
+
total_minutes = 60
|
| 434 |
+
else:
|
| 435 |
+
total_minutes = 60
|
| 436 |
+
else:
|
| 437 |
+
import re
|
| 438 |
+
minutes = re.findall(r'(\d+)', time_str)
|
| 439 |
+
total_minutes = int(minutes[0]) if minutes else 60
|
| 440 |
+
|
| 441 |
+
if total_minutes <= max_time:
|
| 442 |
+
quick_recipes.append((recipe_info['english_name'], recipe_info['telugu_name']))
|
| 443 |
+
|
| 444 |
+
if not quick_recipes:
|
| 445 |
+
return f"❌ {get_translation('no_recipes_under_time', current_language)} {max_time} {get_translation('minutes', current_language)}"
|
| 446 |
+
|
| 447 |
+
result = f"⚡ **{get_translation('recipes_under_time', current_language)} {max_time} {get_translation('minutes', current_language)}:**\n\n"
|
| 448 |
+
for i, (eng_name, tel_name) in enumerate(quick_recipes, 1):
|
| 449 |
+
if current_language == 'English':
|
| 450 |
+
result += f"{i}. **{eng_name}**\n"
|
| 451 |
+
else:
|
| 452 |
+
result += f"{i}. **{eng_name}** | **{tel_name}**\n"
|
| 453 |
+
return result
|
| 454 |
+
|
| 455 |
+
def get_recipe_by_category(current_language="English"):
|
| 456 |
+
"""Get recipes organized by category"""
|
| 457 |
+
categories = {
|
| 458 |
+
get_translation('curry_dishes', current_language): [],
|
| 459 |
+
get_translation('rice_dishes', current_language): [],
|
| 460 |
+
get_translation('egg_dishes', current_language): []
|
| 461 |
+
}
|
| 462 |
+
|
| 463 |
+
for recipe_key, recipe_info in recipes_data.items():
|
| 464 |
+
name_lower = recipe_info['english_name'].lower()
|
| 465 |
+
if 'curry' in name_lower:
|
| 466 |
+
categories[get_translation('curry_dishes', current_language)].append((recipe_info['english_name'], recipe_info['telugu_name']))
|
| 467 |
+
elif 'biryani' in name_lower:
|
| 468 |
+
categories[get_translation('rice_dishes', current_language)].append((recipe_info['english_name'], recipe_info['telugu_name']))
|
| 469 |
+
elif 'egg' in name_lower or 'omelette' in name_lower:
|
| 470 |
+
categories[get_translation('egg_dishes', current_language)].append((recipe_info['english_name'], recipe_info['telugu_name']))
|
| 471 |
+
|
| 472 |
+
result = f"🍽️ **{get_translation('recipe_categories', current_language)}:**\n\n"
|
| 473 |
+
for category, recipes in categories.items():
|
| 474 |
+
if recipes:
|
| 475 |
+
result += f"**{category}:**\n"
|
| 476 |
+
for i, (eng_name, tel_name) in enumerate(recipes, 1):
|
| 477 |
+
if current_language == 'English':
|
| 478 |
+
result += f" {i}. {eng_name}\n"
|
| 479 |
+
else:
|
| 480 |
+
result += f" {i}. {eng_name} | {tel_name}\n"
|
| 481 |
+
result += "\n"
|
| 482 |
+
return result
|
| 483 |
+
|
| 484 |
+
def change_language(new_language, current_search, current_time):
|
| 485 |
+
"""Change the interface language and update all content"""
|
| 486 |
+
new_translations = TRANSLATIONS[new_language]
|
| 487 |
+
|
| 488 |
+
# Update search results if there's current search
|
| 489 |
+
search_title = ""
|
| 490 |
+
search_time = ""
|
| 491 |
+
search_ingredients = ""
|
| 492 |
+
search_bilingual = ""
|
| 493 |
+
search_image =
|