Spaces:
Sleeping
Sleeping
File size: 1,785 Bytes
87edca7 27c3f18 87edca7 519b8f4 6004aaf 0a794f0 b4e8b9d 0a794f0 87edca7 1280140 0082516 a00706b 50f2321 a00706b 27c3f18 1280140 0a794f0 c411eff 0a794f0 87edca7 0a794f0 1280140 0a794f0 1280140 0a794f0 87edca7 0a794f0 87edca7 b4e8b9d 87edca7 3bb9502 |
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 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 |
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()
|