File size: 1,147 Bytes
8ba7ad7
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
import os
from huggingface_hub import InferenceClient

# We use Stable Diffusion XL for high-quality 3D results
MODEL_ID = "stabilityai/stable-diffusion-xl-base-1.0"

def generate_food_image(dish_name):
    """
    Generates a realistic image of the food on a table using HF Inference API.
    """
    token = os.getenv("HF_TOKEN")
    if not token:
        return None, "⚠️ Error: HF_TOKEN not found in Secrets. Please add it in Space Settings."

    try:
        client = InferenceClient(model=MODEL_ID, token=token)
        
        # We specifically prompt for "on a restaurant table" and "3d render style"
        prompt = (
            f"professional food photography of delicious {dish_name} served on a rustic wooden restaurant table, "
            "4k resolution, cinematic lighting, photorealistic, 3d render style, steam rising, gourmet plating, "
            "blurred restaurant background, bokeh"
        )
        
        # Generate the image
        image = client.text_to_image(prompt)
        return image, "✅ Success: Image generated!"
        
    except Exception as e:
        return None, f"❌ Generation Failed: {e}"