Delete v3.txt
Browse files
v3.txt
DELETED
|
@@ -1,827 +0,0 @@
|
|
| 1 |
-
import gradio as gr
|
| 2 |
-
import base64
|
| 3 |
-
import requests
|
| 4 |
-
import io
|
| 5 |
-
from PIL import Image
|
| 6 |
-
import json
|
| 7 |
-
import os
|
| 8 |
-
from together import Together
|
| 9 |
-
import tempfile
|
| 10 |
-
import uuid
|
| 11 |
-
import time
|
| 12 |
-
|
| 13 |
-
def encode_image_to_base64(image_path):
|
| 14 |
-
"""Convert image to base64 encoding"""
|
| 15 |
-
with open(image_path, "rb") as image_file:
|
| 16 |
-
return base64.b64encode(image_file.read()).decode('utf-8')
|
| 17 |
-
|
| 18 |
-
def analyze_single_image(client, img_path):
|
| 19 |
-
"""Analyze a single image to identify ingredients"""
|
| 20 |
-
system_prompt = """You are a culinary expert AI assistant that specializes in identifying ingredients in images.
|
| 21 |
-
Your task is to analyze the provided image and list all the food ingredients you can identify.
|
| 22 |
-
Be specific and detailed about what you see. Only list ingredients, don't suggest recipes yet."""
|
| 23 |
-
|
| 24 |
-
user_prompt = "Please identify all the food ingredients visible in this image. List each ingredient on a new line."
|
| 25 |
-
|
| 26 |
-
try:
|
| 27 |
-
with open(img_path, "rb") as image_file:
|
| 28 |
-
base64_image = base64.b64encode(image_file.read()).decode('utf-8')
|
| 29 |
-
|
| 30 |
-
content = [
|
| 31 |
-
{"type": "text", "text": user_prompt},
|
| 32 |
-
{
|
| 33 |
-
"type": "image_url",
|
| 34 |
-
"image_url": {
|
| 35 |
-
"url": f"data:image/jpeg;base64,{base64_image}"
|
| 36 |
-
}
|
| 37 |
-
}
|
| 38 |
-
]
|
| 39 |
-
|
| 40 |
-
response = client.chat.completions.create(
|
| 41 |
-
model="meta-llama/Llama-Vision-Free",
|
| 42 |
-
messages=[
|
| 43 |
-
{"role": "system", "content": system_prompt},
|
| 44 |
-
{"role": "user", "content": content}
|
| 45 |
-
],
|
| 46 |
-
max_tokens=500,
|
| 47 |
-
temperature=0.2
|
| 48 |
-
)
|
| 49 |
-
|
| 50 |
-
return response.choices[0].message.content
|
| 51 |
-
except Exception as e:
|
| 52 |
-
return f"Error analyzing image: {str(e)}"
|
| 53 |
-
|
| 54 |
-
def format_ingredients_html(all_ingredients):
|
| 55 |
-
"""Format the identified ingredients in HTML"""
|
| 56 |
-
html_content = """
|
| 57 |
-
<div class="ingredients-identified">
|
| 58 |
-
<h2>📋 Ingredients Identified</h2>
|
| 59 |
-
"""
|
| 60 |
-
|
| 61 |
-
for i, ingredients in enumerate(all_ingredients):
|
| 62 |
-
html_content += f"""
|
| 63 |
-
<div class="ingredient-group">
|
| 64 |
-
<h3>Image {i+1} Ingredients</h3>
|
| 65 |
-
<ul class="ingredient-list">
|
| 66 |
-
"""
|
| 67 |
-
|
| 68 |
-
# Split ingredients by new line and create list items
|
| 69 |
-
ingredient_lines = ingredients.strip().split('\n')
|
| 70 |
-
for line in ingredient_lines:
|
| 71 |
-
if line.strip():
|
| 72 |
-
html_content += f"<li>{line.strip()}</li>\n"
|
| 73 |
-
|
| 74 |
-
html_content += """
|
| 75 |
-
</ul>
|
| 76 |
-
</div>
|
| 77 |
-
"""
|
| 78 |
-
|
| 79 |
-
html_content += "</div>"
|
| 80 |
-
return html_content
|
| 81 |
-
|
| 82 |
-
def format_recipe_to_html(recipe_text):
|
| 83 |
-
"""Convert the recipe text to formatted HTML"""
|
| 84 |
-
# Initialize the HTML content with the recipe suggestions header
|
| 85 |
-
html_content = """
|
| 86 |
-
<div class="recipe-suggestions">
|
| 87 |
-
<h2>🍽️ Recipe Suggestions</h2>
|
| 88 |
-
"""
|
| 89 |
-
|
| 90 |
-
# Split the text by recipe (assume recipes are separated by a recipe name heading)
|
| 91 |
-
recipe_sections = []
|
| 92 |
-
current_recipe = ""
|
| 93 |
-
lines = recipe_text.split('\n')
|
| 94 |
-
|
| 95 |
-
# Process lines to identify recipe sections
|
| 96 |
-
for line in lines:
|
| 97 |
-
if line.strip().startswith(("Recipe ", "# ", "## ", "### ")):
|
| 98 |
-
# If we've collected some content for a recipe, save it
|
| 99 |
-
if current_recipe:
|
| 100 |
-
recipe_sections.append(current_recipe)
|
| 101 |
-
current_recipe = ""
|
| 102 |
-
|
| 103 |
-
# Add line to current recipe
|
| 104 |
-
current_recipe += line + "\n"
|
| 105 |
-
|
| 106 |
-
# Add the last recipe if exists
|
| 107 |
-
if current_recipe:
|
| 108 |
-
recipe_sections.append(current_recipe)
|
| 109 |
-
|
| 110 |
-
# Process each recipe section into HTML
|
| 111 |
-
for recipe in recipe_sections:
|
| 112 |
-
if not recipe.strip():
|
| 113 |
-
continue
|
| 114 |
-
|
| 115 |
-
html_content += '<div class="recipe-card">'
|
| 116 |
-
|
| 117 |
-
lines = recipe.split('\n')
|
| 118 |
-
in_ingredients = False
|
| 119 |
-
in_instructions = False
|
| 120 |
-
|
| 121 |
-
for line in lines:
|
| 122 |
-
# Handle recipe title
|
| 123 |
-
if any(x in line.lower() for x in ["recipe ", "# recipe"]) or line.strip().startswith(("# ", "## ")):
|
| 124 |
-
title = line.replace("#", "").replace("Recipe:", "").replace("Recipe", "").strip()
|
| 125 |
-
html_content += f'<h3 class="recipe-title">{title}</h3>\n'
|
| 126 |
-
continue
|
| 127 |
-
|
| 128 |
-
# Handle description
|
| 129 |
-
if "description" in line.lower() and ":" in line:
|
| 130 |
-
description = line.split(":", 1)[1].strip()
|
| 131 |
-
html_content += f'<p class="recipe-description">{description}</p>\n'
|
| 132 |
-
continue
|
| 133 |
-
|
| 134 |
-
# Start ingredients section
|
| 135 |
-
if "ingredients" in line.lower() and not in_ingredients:
|
| 136 |
-
in_ingredients = True
|
| 137 |
-
in_instructions = False
|
| 138 |
-
html_content += '<div class="recipe-ingredients">\n'
|
| 139 |
-
html_content += '<h4>Ingredients</h4>\n<ul>\n'
|
| 140 |
-
continue
|
| 141 |
-
|
| 142 |
-
# Start instructions section
|
| 143 |
-
if any(x in line.lower() for x in ["instructions", "directions", "steps", "preparation"]) and not in_instructions:
|
| 144 |
-
if in_ingredients:
|
| 145 |
-
html_content += '</ul>\n</div>\n'
|
| 146 |
-
in_ingredients = False
|
| 147 |
-
|
| 148 |
-
in_instructions = True
|
| 149 |
-
html_content += '<div class="recipe-instructions">\n'
|
| 150 |
-
html_content += '<h4>Instructions</h4>\n<ol>\n'
|
| 151 |
-
continue
|
| 152 |
-
|
| 153 |
-
# Handle cooking time
|
| 154 |
-
if "cooking time" in line.lower() or "prep time" in line.lower() or "time" in line.lower():
|
| 155 |
-
if in_ingredients:
|
| 156 |
-
html_content += '</ul>\n</div>\n'
|
| 157 |
-
in_ingredients = False
|
| 158 |
-
if in_instructions:
|
| 159 |
-
html_content += '</ol>\n</div>\n'
|
| 160 |
-
in_instructions = False
|
| 161 |
-
|
| 162 |
-
time_info = line.strip()
|
| 163 |
-
html_content += f'<p class="recipe-time"><strong>⏱️ {time_info}</strong></p>\n'
|
| 164 |
-
continue
|
| 165 |
-
|
| 166 |
-
# Handle difficulty level
|
| 167 |
-
if "difficulty" in line.lower():
|
| 168 |
-
difficulty = line.strip()
|
| 169 |
-
html_content += f'<p class="recipe-difficulty"><strong>🔍 {difficulty}</strong></p>\n'
|
| 170 |
-
continue
|
| 171 |
-
|
| 172 |
-
# Handle nutritional info
|
| 173 |
-
if "nutritional" in line.lower():
|
| 174 |
-
if in_ingredients:
|
| 175 |
-
html_content += '</ul>\n</div>\n'
|
| 176 |
-
in_ingredients = False
|
| 177 |
-
if in_instructions:
|
| 178 |
-
html_content += '</ol>\n</div>\n'
|
| 179 |
-
in_instructions = False
|
| 180 |
-
|
| 181 |
-
html_content += '<div class="recipe-nutrition">\n'
|
| 182 |
-
html_content += f'<h4>{line.strip()}</h4>\n<ul>\n'
|
| 183 |
-
continue
|
| 184 |
-
|
| 185 |
-
# Process ingredient line
|
| 186 |
-
if in_ingredients and line.strip() and not line.lower().startswith(("ingredients", "instructions")):
|
| 187 |
-
item = line.strip()
|
| 188 |
-
if item.startswith("- "):
|
| 189 |
-
item = item[2:]
|
| 190 |
-
elif item.startswith("* "):
|
| 191 |
-
item = item[2:]
|
| 192 |
-
|
| 193 |
-
if item:
|
| 194 |
-
html_content += f'<li>{item}</li>\n'
|
| 195 |
-
continue
|
| 196 |
-
|
| 197 |
-
# Process instruction line
|
| 198 |
-
if in_instructions and line.strip() and not line.lower().startswith(("ingredients", "instructions")):
|
| 199 |
-
step = line.strip()
|
| 200 |
-
if step.startswith("- "):
|
| 201 |
-
step = step[2:]
|
| 202 |
-
elif step.startswith("* "):
|
| 203 |
-
step = step[2:]
|
| 204 |
-
elif step.startswith(". "):
|
| 205 |
-
step = step[2:]
|
| 206 |
-
elif step[0].isdigit() and step[1] in [".", ")"]:
|
| 207 |
-
step = step[2:].strip()
|
| 208 |
-
|
| 209 |
-
if step:
|
| 210 |
-
html_content += f'<li>{step}</li>\n'
|
| 211 |
-
continue
|
| 212 |
-
|
| 213 |
-
# Process nutrition line
|
| 214 |
-
if "nutritional" in line.lower() and line.strip() and not line.startswith(("ingredients", "instructions")):
|
| 215 |
-
item = line.strip()
|
| 216 |
-
if item.startswith("- "):
|
| 217 |
-
item = item[2:]
|
| 218 |
-
elif item.startswith("* "):
|
| 219 |
-
item = item[2:]
|
| 220 |
-
|
| 221 |
-
if item and not item.lower().startswith("nutritional"):
|
| 222 |
-
html_content += f'<li>{item}</li>\n'
|
| 223 |
-
continue
|
| 224 |
-
|
| 225 |
-
# Close any open sections
|
| 226 |
-
if in_ingredients:
|
| 227 |
-
html_content += '</ul>\n</div>\n'
|
| 228 |
-
if in_instructions:
|
| 229 |
-
html_content += '</ol>\n</div>\n'
|
| 230 |
-
|
| 231 |
-
html_content += '</div>\n' # Close recipe card
|
| 232 |
-
|
| 233 |
-
html_content += '</div>\n' # Close recipe suggestions div
|
| 234 |
-
|
| 235 |
-
return html_content
|
| 236 |
-
|
| 237 |
-
def get_recipe_suggestions(api_key, image_paths, num_recipes=3, dietary_restrictions="None", cuisine_preference="Any"):
|
| 238 |
-
"""Get recipe suggestions based on the uploaded images of ingredients"""
|
| 239 |
-
if not api_key:
|
| 240 |
-
return "Please provide your Together API key."
|
| 241 |
-
|
| 242 |
-
if not image_paths or len(image_paths) == 0:
|
| 243 |
-
return "Please upload at least one image of ingredients."
|
| 244 |
-
|
| 245 |
-
try:
|
| 246 |
-
client = Together(api_key=api_key)
|
| 247 |
-
|
| 248 |
-
all_ingredients = []
|
| 249 |
-
for img_path in image_paths:
|
| 250 |
-
ingredients_text = analyze_single_image(client, img_path)
|
| 251 |
-
all_ingredients.append(ingredients_text)
|
| 252 |
-
|
| 253 |
-
combined_ingredients = "\n\n".join([f"Image {i+1} ingredients:\n{ingredients}"
|
| 254 |
-
for i, ingredients in enumerate(all_ingredients)])
|
| 255 |
-
|
| 256 |
-
system_prompt = """You are a culinary expert AI assistant that specializes in creating recipes based on available ingredients.
|
| 257 |
-
You will be provided with lists of ingredients identified from multiple images. Your task is to suggest creative,
|
| 258 |
-
detailed recipes that use as many of the identified ingredients as possible.
|
| 259 |
-
|
| 260 |
-
For each recipe suggestion, include:
|
| 261 |
-
1. Recipe name
|
| 262 |
-
2. Brief description of the dish
|
| 263 |
-
3. Complete ingredients list (including estimated quantities and any additional staple ingredients that might be needed)
|
| 264 |
-
4. Step-by-step cooking instructions
|
| 265 |
-
5. Approximate cooking time
|
| 266 |
-
6. Difficulty level (Easy, Medium, Advanced)
|
| 267 |
-
7. Nutritional highlights
|
| 268 |
-
|
| 269 |
-
Format each recipe clearly with headings for each section. Make sure to separate recipes clearly.
|
| 270 |
-
Consider any dietary restrictions and cuisine preferences mentioned by the user."""
|
| 271 |
-
|
| 272 |
-
user_prompt = f"""Based on the following ingredients identified from multiple images, suggest {num_recipes} creative and delicious recipes.
|
| 273 |
-
|
| 274 |
-
{combined_ingredients}
|
| 275 |
-
|
| 276 |
-
Dietary restrictions to consider: {dietary_restrictions}
|
| 277 |
-
Cuisine preference: {cuisine_preference}
|
| 278 |
-
|
| 279 |
-
Please be creative with your recipe suggestions and try to use ingredients from multiple images if possible."""
|
| 280 |
-
|
| 281 |
-
response = client.chat.completions.create(
|
| 282 |
-
model="meta-llama/Llama-Vision-Free",
|
| 283 |
-
messages=[
|
| 284 |
-
{"role": "system", "content": system_prompt},
|
| 285 |
-
{"role": "user", "content": user_prompt}
|
| 286 |
-
],
|
| 287 |
-
max_tokens=20000,
|
| 288 |
-
temperature=0.7
|
| 289 |
-
)
|
| 290 |
-
|
| 291 |
-
recipe_text = response.choices[0].message.content
|
| 292 |
-
|
| 293 |
-
# Format ingredients and recipes as HTML
|
| 294 |
-
ingredients_html = format_ingredients_html(all_ingredients)
|
| 295 |
-
recipes_html = format_recipe_to_html(recipe_text)
|
| 296 |
-
|
| 297 |
-
# Combine HTML content
|
| 298 |
-
html_content = ingredients_html + "<hr>" + recipes_html
|
| 299 |
-
|
| 300 |
-
# Create a downloadable HTML file with styling
|
| 301 |
-
full_html = create_downloadable_html(ingredients_html, recipes_html, dietary_restrictions, cuisine_preference)
|
| 302 |
-
|
| 303 |
-
# Generate a unique filename for the downloadable HTML
|
| 304 |
-
timestamp = int(time.time())
|
| 305 |
-
file_name = f"recipes_{timestamp}.html"
|
| 306 |
-
file_path = os.path.join(tempfile.gettempdir(), file_name)
|
| 307 |
-
|
| 308 |
-
with open(file_path, "w", encoding="utf-8") as f:
|
| 309 |
-
f.write(full_html)
|
| 310 |
-
|
| 311 |
-
return [html_content, file_path]
|
| 312 |
-
except Exception as e:
|
| 313 |
-
return [f"Error: {str(e)}", None]
|
| 314 |
-
|
| 315 |
-
def create_downloadable_html(ingredients_html, recipes_html, dietary_restrictions, cuisine_preference):
|
| 316 |
-
"""Create a complete HTML document with styling for download"""
|
| 317 |
-
html = f"""<!DOCTYPE html>
|
| 318 |
-
<html lang="en">
|
| 319 |
-
<head>
|
| 320 |
-
<meta charset="UTF-8">
|
| 321 |
-
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
| 322 |
-
<title>Your Personalized Recipes</title>
|
| 323 |
-
<style>
|
| 324 |
-
@import url('https://fonts.googleapis.com/css2?family=Poppins:wght@300;400;500;600;700&display=swap');
|
| 325 |
-
:root {{
|
| 326 |
-
--primary-color: #FF6F61;
|
| 327 |
-
--secondary-color: #4BB543;
|
| 328 |
-
--accent-color: #F0A500;
|
| 329 |
-
--background-color: #F4F4F9;
|
| 330 |
-
--text-color: #333333;
|
| 331 |
-
--card-background: #FFFFFF;
|
| 332 |
-
--border-radius: 12px;
|
| 333 |
-
--box-shadow: rgba(0, 0, 0, 0.1) 0px 4px 20px;
|
| 334 |
-
}}
|
| 335 |
-
body {{
|
| 336 |
-
font-family: 'Poppins', sans-serif;
|
| 337 |
-
background-color: var(--background-color);
|
| 338 |
-
color: var(--text-color);
|
| 339 |
-
margin: 0;
|
| 340 |
-
padding: 0;
|
| 341 |
-
line-height: 1.6;
|
| 342 |
-
}}
|
| 343 |
-
.container {{
|
| 344 |
-
max-width: 1000px;
|
| 345 |
-
margin: 0 auto;
|
| 346 |
-
padding: 20px;
|
| 347 |
-
}}
|
| 348 |
-
header {{
|
| 349 |
-
background-color: var(--primary-color);
|
| 350 |
-
color: white;
|
| 351 |
-
padding: 40px 20px;
|
| 352 |
-
text-align: center;
|
| 353 |
-
border-radius: 0 0 20px 20px;
|
| 354 |
-
margin-bottom: 30px;
|
| 355 |
-
}}
|
| 356 |
-
h1 {{
|
| 357 |
-
font-size: 2.5em;
|
| 358 |
-
margin-bottom: 10px;
|
| 359 |
-
}}
|
| 360 |
-
.recipe-info {{
|
| 361 |
-
display: flex;
|
| 362 |
-
justify-content: center;
|
| 363 |
-
gap: 20px;
|
| 364 |
-
margin-bottom: 20px;
|
| 365 |
-
flex-wrap: wrap;
|
| 366 |
-
}}
|
| 367 |
-
.info-badge {{
|
| 368 |
-
background-color: rgba(255, 255, 255, 0.2);
|
| 369 |
-
padding: 8px 16px;
|
| 370 |
-
border-radius: 20px;
|
| 371 |
-
font-size: 0.9em;
|
| 372 |
-
}}
|
| 373 |
-
.ingredients-identified, .recipe-suggestions {{
|
| 374 |
-
background-color: var(--card-background);
|
| 375 |
-
border-radius: var(--border-radius);
|
| 376 |
-
padding: 25px;
|
| 377 |
-
margin-bottom: 30px;
|
| 378 |
-
box-shadow: var(--box-shadow);
|
| 379 |
-
}}
|
| 380 |
-
h2 {{
|
| 381 |
-
color: var(--primary-color);
|
| 382 |
-
border-bottom: 2px solid var(--primary-color);
|
| 383 |
-
padding-bottom: 10px;
|
| 384 |
-
margin-top: 0;
|
| 385 |
-
}}
|
| 386 |
-
.ingredient-group {{
|
| 387 |
-
margin-bottom: 20px;
|
| 388 |
-
}}
|
| 389 |
-
h3 {{
|
| 390 |
-
color: var(--accent-color);
|
| 391 |
-
margin-bottom: 10px;
|
| 392 |
-
}}
|
| 393 |
-
.ingredient-list {{
|
| 394 |
-
list-style-type: disc;
|
| 395 |
-
padding-left: 20px;
|
| 396 |
-
}}
|
| 397 |
-
.recipe-card {{
|
| 398 |
-
background-color: #f9f9f9;
|
| 399 |
-
border-radius: var(--border-radius);
|
| 400 |
-
padding: 20px;
|
| 401 |
-
margin-bottom: 30px;
|
| 402 |
-
box-shadow: 0 2px 10px rgba(0, 0, 0, 0.05);
|
| 403 |
-
}}
|
| 404 |
-
.recipe-title {{
|
| 405 |
-
color: var(--secondary-color);
|
| 406 |
-
font-size: 1.8em;
|
| 407 |
-
margin-top: 0;
|
| 408 |
-
margin-bottom: 15px;
|
| 409 |
-
}}
|
| 410 |
-
.recipe-description {{
|
| 411 |
-
font-style: italic;
|
| 412 |
-
margin-bottom: 20px;
|
| 413 |
-
color: #666;
|
| 414 |
-
}}
|
| 415 |
-
.recipe-ingredients, .recipe-instructions, .recipe-nutrition {{
|
| 416 |
-
margin-bottom: 20px;
|
| 417 |
-
}}
|
| 418 |
-
.recipe-ingredients h4, .recipe-instructions h4, .recipe-nutrition h4 {{
|
| 419 |
-
color: var(--primary-color);
|
| 420 |
-
margin-bottom: 10px;
|
| 421 |
-
}}
|
| 422 |
-
.recipe-ingredients ul {{
|
| 423 |
-
list-style-type: disc;
|
| 424 |
-
}}
|
| 425 |
-
.recipe-instructions ol {{
|
| 426 |
-
padding-left: 20px;
|
| 427 |
-
}}
|
| 428 |
-
.recipe-instructions li {{
|
| 429 |
-
margin-bottom: 10px;
|
| 430 |
-
}}
|
| 431 |
-
.recipe-time, .recipe-difficulty {{
|
| 432 |
-
color: #666;
|
| 433 |
-
margin: 10px 0;
|
| 434 |
-
}}
|
| 435 |
-
hr {{
|
| 436 |
-
border: 0;
|
| 437 |
-
height: 1px;
|
| 438 |
-
background-image: linear-gradient(to right, rgba(0, 0, 0, 0), rgba(0, 0, 0, 0.2), rgba(0, 0, 0, 0));
|
| 439 |
-
margin: 30px 0;
|
| 440 |
-
}}
|
| 441 |
-
footer {{
|
| 442 |
-
text-align: center;
|
| 443 |
-
margin-top: 50px;
|
| 444 |
-
padding: 20px;
|
| 445 |
-
color: #666;
|
| 446 |
-
font-size: 0.9em;
|
| 447 |
-
}}
|
| 448 |
-
</style>
|
| 449 |
-
</head>
|
| 450 |
-
<body>
|
| 451 |
-
<header>
|
| 452 |
-
<h1>🍲 Your Personalized Recipes</h1>
|
| 453 |
-
<div class="recipe-info">
|
| 454 |
-
<span class="info-badge">Dietary: {dietary_restrictions}</span>
|
| 455 |
-
<span class="info-badge">Cuisine: {cuisine_preference}</span>
|
| 456 |
-
<span class="info-badge">Generated: {time.strftime("%Y-%m-%d")}</span>
|
| 457 |
-
</div>
|
| 458 |
-
</header>
|
| 459 |
-
|
| 460 |
-
<div class="container">
|
| 461 |
-
{ingredients_html}
|
| 462 |
-
|
| 463 |
-
<hr>
|
| 464 |
-
|
| 465 |
-
{recipes_html}
|
| 466 |
-
|
| 467 |
-
<footer>
|
| 468 |
-
<p>Generated by Visual Recipe Assistant</p>
|
| 469 |
-
<p>Powered by Meta's Llama-Vision-Free Model & Together AI</p>
|
| 470 |
-
</footer>
|
| 471 |
-
</div>
|
| 472 |
-
</body>
|
| 473 |
-
</html>
|
| 474 |
-
"""
|
| 475 |
-
return html
|
| 476 |
-
|
| 477 |
-
def update_gallery(files):
|
| 478 |
-
"""Update the gallery with uploaded image paths"""
|
| 479 |
-
if not files or len(files) == 0:
|
| 480 |
-
return gr.update(visible=False)
|
| 481 |
-
return gr.update(value=files, visible=True)
|
| 482 |
-
|
| 483 |
-
def process_recipe_request(api_key, files, num_recipes, dietary_restrictions, cuisine_preference):
|
| 484 |
-
"""Process the recipe request with uploaded files"""
|
| 485 |
-
if not files:
|
| 486 |
-
return ["Please upload at least one image of ingredients.", None]
|
| 487 |
-
return get_recipe_suggestions(api_key, files, num_recipes, dietary_restrictions, cuisine_preference)
|
| 488 |
-
|
| 489 |
-
custom_css = """
|
| 490 |
-
@import url('https://fonts.googleapis.com/css2?family=Poppins:wght@300;400;500;600;700&display=swap');
|
| 491 |
-
:root {
|
| 492 |
-
--primary-color: #FF6F61; /* Warm coral */
|
| 493 |
-
--secondary-color: #4BB543; /* Fresh green */
|
| 494 |
-
--accent-color: #F0A500; /* Golden yellow */
|
| 495 |
-
--background-color: #F4F4F9; /* Light grayish background */
|
| 496 |
-
--text-color: #333333; /* Dark gray text */
|
| 497 |
-
--card-background: #FFFFFF; /* White for cards */
|
| 498 |
-
--border-radius: 12px;
|
| 499 |
-
--font-family: 'Poppins', sans-serif;
|
| 500 |
-
--box-shadow: rgba(0, 0, 0, 0.1) 0px 4px 20px;
|
| 501 |
-
--hover-shadow: rgba(0, 0, 0, 0.15) 0px 8px 30px;
|
| 502 |
-
}
|
| 503 |
-
body {
|
| 504 |
-
font-family: var(--font-family);
|
| 505 |
-
background-color: var(--background-color);
|
| 506 |
-
color: var(--text-color);
|
| 507 |
-
margin: 0;
|
| 508 |
-
padding: 0;
|
| 509 |
-
}
|
| 510 |
-
.container {
|
| 511 |
-
width: 100%;
|
| 512 |
-
margin: 0 auto;
|
| 513 |
-
padding: 20px;
|
| 514 |
-
}
|
| 515 |
-
.app-header {
|
| 516 |
-
background-color: var(--primary-color);
|
| 517 |
-
color: white;
|
| 518 |
-
padding: 60px 20px;
|
| 519 |
-
text-align: center;
|
| 520 |
-
border-radius: 0 0 30px 30px;
|
| 521 |
-
box-shadow: var(--box-shadow);
|
| 522 |
-
width: 100%;
|
| 523 |
-
}
|
| 524 |
-
.app-title {
|
| 525 |
-
font-size: 2.8em;
|
| 526 |
-
font-weight: 700;
|
| 527 |
-
margin-bottom: 10px;
|
| 528 |
-
}
|
| 529 |
-
.app-subtitle {
|
| 530 |
-
font-size: 1.3em;
|
| 531 |
-
font-weight: 400;
|
| 532 |
-
max-width: 800px;
|
| 533 |
-
margin: 0 auto;
|
| 534 |
-
}
|
| 535 |
-
.input-section, .output-section {
|
| 536 |
-
background-color: var(--card-background);
|
| 537 |
-
border-radius: var(--border-radius);
|
| 538 |
-
padding: 30px;
|
| 539 |
-
box-shadow: var(--box-shadow);
|
| 540 |
-
margin-bottom: 30px;
|
| 541 |
-
width: 100%;
|
| 542 |
-
}
|
| 543 |
-
.section-header {
|
| 544 |
-
font-size: 1.6em;
|
| 545 |
-
font-weight: 600;
|
| 546 |
-
color: var(--text-color);
|
| 547 |
-
margin-bottom: 20px;
|
| 548 |
-
border-bottom: 2px solid var(--primary-color);
|
| 549 |
-
padding-bottom: 10px;
|
| 550 |
-
}
|
| 551 |
-
.section-header2 {
|
| 552 |
-
font-size: 1.6em;
|
| 553 |
-
font-weight: 600;
|
| 554 |
-
color: var(--text-color);
|
| 555 |
-
border-bottom: 2px solid var(--primary-color);
|
| 556 |
-
padding-bottom: 10px;
|
| 557 |
-
}
|
| 558 |
-
.image-upload-container {
|
| 559 |
-
border: 2px dashed var(--secondary-color);
|
| 560 |
-
padding: 40px;
|
| 561 |
-
text-align: center;
|
| 562 |
-
background-color: rgba(75, 181, 67, 0.1);
|
| 563 |
-
transition: all 0.3s ease;
|
| 564 |
-
}
|
| 565 |
-
.image-upload-container:hover {
|
| 566 |
-
border-color: var(--primary-color);
|
| 567 |
-
background-color: rgba(255, 111, 97, 0.1);
|
| 568 |
-
}
|
| 569 |
-
button.primary-button {
|
| 570 |
-
background-color: var(--primary-color);
|
| 571 |
-
color: white;
|
| 572 |
-
border: none;
|
| 573 |
-
padding: 16px 32px;
|
| 574 |
-
border-radius: 6px;
|
| 575 |
-
font-size: 1.1em;
|
| 576 |
-
cursor: pointer;
|
| 577 |
-
transition: all 0.3s ease;
|
| 578 |
-
width: 100%;
|
| 579 |
-
box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
|
| 580 |
-
}
|
| 581 |
-
button.primary-button:hover {
|
| 582 |
-
background-color: #E15F52;
|
| 583 |
-
box-shadow: var(--hover-shadow);
|
| 584 |
-
}
|
| 585 |
-
button.download-button {
|
| 586 |
-
background-color: var(--secondary-color);
|
| 587 |
-
color: white;
|
| 588 |
-
border: none;
|
| 589 |
-
padding: 12px 24px;
|
| 590 |
-
border-radius: 6px;
|
| 591 |
-
font-size: 1em;
|
| 592 |
-
cursor: pointer;
|
| 593 |
-
transition: all 0.3s ease;
|
| 594 |
-
margin-top: 15px;
|
| 595 |
-
display: flex;
|
| 596 |
-
align-items: center;
|
| 597 |
-
justify-content: center;
|
| 598 |
-
gap: 8px;
|
| 599 |
-
margin-left: auto;
|
| 600 |
-
margin-right: auto;
|
| 601 |
-
margin-bottom: 25px !important;
|
| 602 |
-
}
|
| 603 |
-
button.download-button:hover {
|
| 604 |
-
background-color: #3da037;
|
| 605 |
-
box-shadow: var(--hover-shadow);
|
| 606 |
-
}
|
| 607 |
-
.gallery-container {
|
| 608 |
-
display: grid;
|
| 609 |
-
grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
|
| 610 |
-
gap: 20px;
|
| 611 |
-
margin-top: 30px;
|
| 612 |
-
}
|
| 613 |
-
.gallery-item {
|
| 614 |
-
border-radius: var(--border-radius);
|
| 615 |
-
overflow: hidden;
|
| 616 |
-
box-shadow: var(--box-shadow);
|
| 617 |
-
transition: transform 0.3s ease;
|
| 618 |
-
aspect-ratio: 1 / 1;
|
| 619 |
-
object-fit: cover;
|
| 620 |
-
}
|
| 621 |
-
.gallery-item:hover {
|
| 622 |
-
transform: scale(1.05);
|
| 623 |
-
box-shadow: var(--hover-shadow);
|
| 624 |
-
}
|
| 625 |
-
.recipe-output {
|
| 626 |
-
font-size: 1.2em;
|
| 627 |
-
line-height: 1.7;
|
| 628 |
-
color: var(--text-color);
|
| 629 |
-
max-height: 600px;
|
| 630 |
-
overflow-y: auto;
|
| 631 |
-
padding-right: 15px;
|
| 632 |
-
}
|
| 633 |
-
.ingredients-identified, .recipe-suggestions {
|
| 634 |
-
background-color: #f9f9f9;
|
| 635 |
-
border-radius: var(--border-radius);
|
| 636 |
-
padding: 20px;
|
| 637 |
-
margin-bottom: 20px;
|
| 638 |
-
}
|
| 639 |
-
.recipe-card {
|
| 640 |
-
background-color: white;
|
| 641 |
-
border-radius: var(--border-radius);
|
| 642 |
-
padding: 20px;
|
| 643 |
-
margin-bottom: 20px;
|
| 644 |
-
box-shadow: 0 2px 8px rgba(0, 0, 0, 0.05);
|
| 645 |
-
}
|
| 646 |
-
.recipe-title {
|
| 647 |
-
color: var(--secondary-color);
|
| 648 |
-
font-size: 1.8em;
|
| 649 |
-
margin-top: 0;
|
| 650 |
-
margin-bottom: 15px;
|
| 651 |
-
}
|
| 652 |
-
.recipe-description {
|
| 653 |
-
font-style: italic;
|
| 654 |
-
margin-bottom: 20px;
|
| 655 |
-
color: #666;
|
| 656 |
-
}
|
| 657 |
-
.recipe-ingredients, .recipe-instructions, .recipe-nutrition {
|
| 658 |
-
margin-bottom: 20px;
|
| 659 |
-
}
|
| 660 |
-
.recipe-ingredients h4, .recipe-instructions h4, .recipe-nutrition h4 {
|
| 661 |
-
color: var(--primary-color);
|
| 662 |
-
margin-bottom: 10px;
|
| 663 |
-
}
|
| 664 |
-
.footer {
|
| 665 |
-
background-color: var(--card-background);
|
| 666 |
-
padding: 40px 20px;
|
| 667 |
-
text-align: center;
|
| 668 |
-
color: var(--text-color);
|
| 669 |
-
font-size: 1.1em;
|
| 670 |
-
box-shadow: 0 -2px 10px rgba(0, 0, 0, 0.05);
|
| 671 |
-
width: 100%;
|
| 672 |
-
}
|
| 673 |
-
.footer-content {
|
| 674 |
-
max-width: 800px;
|
| 675 |
-
margin: 0 auto;
|
| 676 |
-
}
|
| 677 |
-
.footer-brand {
|
| 678 |
-
font-weight: 700;
|
| 679 |
-
color: var(--primary-color);
|
| 680 |
-
}
|
| 681 |
-
.footer-links a {
|
| 682 |
-
color: var(--secondary-color);
|
| 683 |
-
text-decoration: none;
|
| 684 |
-
margin: 0 15px;
|
| 685 |
-
transition: color 0.3s ease;
|
| 686 |
-
}
|
| 687 |
-
.footer-links a:hover {
|
| 688 |
-
color: var(--primary-color);
|
| 689 |
-
}
|
| 690 |
-
"""
|
| 691 |
-
|
| 692 |
-
html_header = """
|
| 693 |
-
<div class="app-header">
|
| 694 |
-
<div class="app-title">🍲 Visual Recipe Assistant</div>
|
| 695 |
-
<div class="app-subtitle">Upload images of ingredients you have on hand and get personalized recipe suggestions powered by AI</div>
|
| 696 |
-
</div>
|
| 697 |
-
"""
|
| 698 |
-
|
| 699 |
-
html_footer = """
|
| 700 |
-
<div class="footer">
|
| 701 |
-
<div class="footer-content">
|
| 702 |
-
<p><span class="footer-brand">🍲 Visual Recipe Assistant</span></p>
|
| 703 |
-
<p>Powered by Meta's Llama-Vision-Free Model & Together AI</p>
|
| 704 |
-
<p>Upload multiple ingredient images for more creative recipe combinations</p>
|
| 705 |
-
<div class="footer-links">
|
| 706 |
-
<a href="#" onclick="document.getElementById('how-to-use').scrollIntoView({ behavior: 'smooth' }); return false;">How It Works</a>
|
| 707 |
-
<a href="https://api.whatsapp.com/send/?phone=%2B8801719296601&text&type=phone_number&app_absent=0" target="_blank">Contact Us</a>
|
| 708 |
-
</div>
|
| 709 |
-
</div>
|
| 710 |
-
</div>
|
| 711 |
-
"""
|
| 712 |
-
|
| 713 |
-
with gr.Blocks(css=custom_css) as app:
|
| 714 |
-
gr.HTML(html_header)
|
| 715 |
-
|
| 716 |
-
with gr.Accordion("How It Works", open=False, elem_id="how-to-use"):
|
| 717 |
-
gr.Markdown("""
|
| 718 |
-
### Getting Started:
|
| 719 |
-
1. Enter your OpenAI API key in the field below and click "Set API Key"
|
| 720 |
-
2. Upload multiple PDF research papers (2 or more recommended)
|
| 721 |
-
3. Enter your review question or topic
|
| 722 |
-
4. Check the "Include Tables" option if you want the review to include comparison tables
|
| 723 |
-
5. Click "Generate Systematic Review" to start the process
|
| 724 |
-
6. After generation, you can download the review as HTML
|
| 725 |
-
|
| 726 |
-
### Tips for Best Results:
|
| 727 |
-
- Upload papers that are related to the same research topic or field
|
| 728 |
-
- Be specific in your review question to get more focused results
|
| 729 |
-
- The generated review will follow a systematic structure including research field identification, data extraction, analysis, and conclusions
|
| 730 |
-
- The more papers you upload, the more comprehensive the review will be
|
| 731 |
-
- The review will be formatted as a professional academic paper with proper sections and citations
|
| 732 |
-
""")
|
| 733 |
-
|
| 734 |
-
# Store the generated html file path for download
|
| 735 |
-
html_file_path = gr.State(None)
|
| 736 |
-
|
| 737 |
-
with gr.Row():
|
| 738 |
-
with gr.Column(scale=1):
|
| 739 |
-
with gr.Group(elem_classes="input-section"):
|
| 740 |
-
gr.HTML('<h3 class="section-header">API Configuration</h3>')
|
| 741 |
-
api_key_input = gr.Textbox(
|
| 742 |
-
label="Together API Key",
|
| 743 |
-
placeholder="Enter your Together API key here...",
|
| 744 |
-
type="password",
|
| 745 |
-
elem_classes="input-group"
|
| 746 |
-
)
|
| 747 |
-
|
| 748 |
-
gr.HTML('<h3 class="section-header">Upload Ingredients</h3>')
|
| 749 |
-
file_upload = gr.File(
|
| 750 |
-
label="Upload images of ingredients",
|
| 751 |
-
file_types=["image"],
|
| 752 |
-
file_count="multiple",
|
| 753 |
-
elem_classes="image-upload-container"
|
| 754 |
-
)
|
| 755 |
-
|
| 756 |
-
image_input = gr.Gallery(
|
| 757 |
-
label="Uploaded Ingredients",
|
| 758 |
-
elem_id="ingredient-gallery",
|
| 759 |
-
columns=3,
|
| 760 |
-
rows=2,
|
| 761 |
-
height="auto",
|
| 762 |
-
visible=False
|
| 763 |
-
)
|
| 764 |
-
|
| 765 |
-
gr.HTML('<h3 class="section-header2">Recipe Preferences</h3>')
|
| 766 |
-
with gr.Row():
|
| 767 |
-
num_recipes = gr.Slider(
|
| 768 |
-
minimum=1,
|
| 769 |
-
maximum=5,
|
| 770 |
-
value=3,
|
| 771 |
-
step=1,
|
| 772 |
-
label="Number of Recipe Suggestions",
|
| 773 |
-
elem_classes="input-group"
|
| 774 |
-
)
|
| 775 |
-
|
| 776 |
-
with gr.Row():
|
| 777 |
-
with gr.Column():
|
| 778 |
-
dietary_restrictions = gr.Dropdown(
|
| 779 |
-
choices=["None", "Vegetarian", "Vegan", "Gluten-Free", "Dairy-Free", "Low-Carb", "Keto", "Paleo"],
|
| 780 |
-
value="None",
|
| 781 |
-
label="Dietary Restrictions",
|
| 782 |
-
elem_classes="input-group"
|
| 783 |
-
)
|
| 784 |
-
|
| 785 |
-
with gr.Column():
|
| 786 |
-
cuisine_preference = gr.Dropdown(
|
| 787 |
-
choices=["Any", "Italian", "Asian", "Mexican", "Mediterranean", "Indian", "American", "French", "Middle Eastern"],
|
| 788 |
-
value="Any",
|
| 789 |
-
label="Cuisine Preference",
|
| 790 |
-
elem_classes="input-group"
|
| 791 |
-
)
|
| 792 |
-
|
| 793 |
-
submit_button = gr.Button("Get Recipe Suggestions", elem_classes="primary-button")
|
| 794 |
-
|
| 795 |
-
with gr.Column(scale=1):
|
| 796 |
-
with gr.Group(elem_classes="output-section"):
|
| 797 |
-
gr.HTML('<h3 class="section-header">Your Personalized Recipes</h3>')
|
| 798 |
-
output = gr.HTML(elem_classes="recipe-output")
|
| 799 |
-
download_button = gr.Button("📥 Download Recipes (See below to download)", elem_classes="download-button", visible=False, elem_id="download-button")
|
| 800 |
-
|
| 801 |
-
gr.HTML(html_footer)
|
| 802 |
-
|
| 803 |
-
# Update functions
|
| 804 |
-
def process_and_update_file_path(api_key, files, num_recipes, dietary_restrictions, cuisine_preference):
|
| 805 |
-
"""Process recipe request and update file path state"""
|
| 806 |
-
result = process_recipe_request(api_key, files, num_recipes, dietary_restrictions, cuisine_preference)
|
| 807 |
-
html_content = result[0]
|
| 808 |
-
file_path = result[1]
|
| 809 |
-
return html_content, file_path, gr.update(visible=file_path is not None)
|
| 810 |
-
|
| 811 |
-
file_upload.change(fn=update_gallery, inputs=file_upload, outputs=image_input)
|
| 812 |
-
|
| 813 |
-
submit_button.click(
|
| 814 |
-
fn=process_and_update_file_path,
|
| 815 |
-
inputs=[api_key_input, file_upload, num_recipes, dietary_restrictions, cuisine_preference],
|
| 816 |
-
outputs=[output, html_file_path, download_button]
|
| 817 |
-
)
|
| 818 |
-
|
| 819 |
-
# Handle download button click
|
| 820 |
-
download_button.click(
|
| 821 |
-
fn=lambda x: x,
|
| 822 |
-
inputs=html_file_path,
|
| 823 |
-
outputs=gr.File(label="Download Recipe HTML")
|
| 824 |
-
)
|
| 825 |
-
|
| 826 |
-
if __name__ == "__main__":
|
| 827 |
-
app.launch()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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