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}"