Spaces:
Runtime error
Runtime error
import gradio as gr | |
from transformers import pipeline | |
import fastapi | |
from gradio import fastapi as gr_api | |
generator = pipeline("text2text-generation", model="LahiruProjects/recipe-generator-flan-t5") | |
def generate_recipe(name, ingredients, calories, time): | |
prompt = f"""Create a step-by-step recipe for "{name}" using these ingredients: {', '.join(ingredients.split(','))}. | |
Keep it under {calories} calories and make sure it's ready in less than {time} minutes.""" | |
result = generator(prompt) | |
return result[0]["generated_text"] | |
# Using gr.Blocks() for a custom interface | |
with gr.Blocks() as demo: | |
with gr.Row(): | |
name = gr.Textbox(label="Recipe Name") | |
ingredients = gr.Textbox(label="Ingredients (comma-separated)") | |
calories = gr.Number(label="Max Calories", value=400) | |
time = gr.Number(label="Max Cooking Time (minutes)", value=30) | |
output = gr.Textbox() | |
demo.add(name, ingredients, calories, time, output) | |
# Set up FastAPI app to expose the REST API | |
app = fastapi.FastAPI() | |
app = gr_api.FastAPI(app, demo) | |
gr_api.add_api_route(app, "/api/predict", demo, methods=["POST"]) | |