Spaces:
Sleeping
Sleeping
| import gradio as gr | |
| import requests | |
| NEBIUS_API_KEY = "NEBIUS_API_KEY" | |
| FOLDER_ID = "FOLDER_ID" | |
| def generate_recipe(dietary_pref, ingredients): | |
| input_text = f"Create a recipe using these ingredients: {ingredients}. It should be {dietary_pref}." | |
| headers = { | |
| "Authorization": f"Api-Key {NEBIUS_API_KEY}", | |
| "Content-Type": "application/json" | |
| } | |
| body = { | |
| "folderId": FOLDER_ID, | |
| "texts": [input_text], | |
| "model": "yandex-lite", | |
| "temperature": 0.6, | |
| "maxTokens": "2000" | |
| } | |
| try: | |
| response = requests.post( | |
| "https://llm.api.cloud.yandex.net/foundationModels/v1/textCompletion", | |
| headers=headers, | |
| json=body | |
| ) | |
| print("RAW RESPONSE:", response.text) | |
| if response.status_code == 200: | |
| result = response.json() | |
| return result["result"]["alternatives"][0]["text"] | |
| else: | |
| return f"API Error {response.status_code}: {response.text}" | |
| except Exception as e: | |
| return f"❌ Error: {e}" | |
| with gr.Blocks(theme=gr.themes.Soft()) as demo: | |
| gr.Markdown("🍳 **AgentChef: AI Recipe Planner & Smart Kitchen Assistant**") | |
| with gr.Row(): | |
| dietary = gr.Dropdown( | |
| label="Dietary Preferences", | |
| choices=["Vegetarian", "Non-Vegetarian", "Vegan", "Keto", "Other"], | |
| value="Vegetarian" | |
| ) | |
| ingredients = gr.Textbox( | |
| label="Ingredients Available", | |
| placeholder="e.g., tomato, onion, garlic, paneer..." | |
| ) | |
| submit = gr.Button("🍽️ Generate Recipe") | |
| recipe_output = gr.Textbox(label="AI-Generated Recipe", lines=10) | |
| submit.click(fn=generate_recipe, inputs=[dietary, ingredients], outputs=recipe_output) | |
| demo.launch() | |