Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -1,7 +1,8 @@
|
|
1 |
import gradio as gr
|
2 |
from transformers import pipeline
|
|
|
|
|
3 |
|
4 |
-
# Load the model (this runs only once!)
|
5 |
generator = pipeline("text2text-generation", model="LahiruProjects/recipe-generator-flan-t5")
|
6 |
|
7 |
def generate_recipe(name, ingredients, calories, time):
|
@@ -10,18 +11,19 @@ def generate_recipe(name, ingredients, calories, time):
|
|
10 |
result = generator(prompt)
|
11 |
return result[0]["generated_text"]
|
12 |
|
13 |
-
#
|
14 |
-
|
15 |
-
|
16 |
-
|
17 |
-
gr.Textbox(label="
|
18 |
-
gr.
|
19 |
-
gr.Number(label="Max
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
)
|
|
|
|
|
26 |
|
27 |
-
iface.launch()
|
|
|
1 |
import gradio as gr
|
2 |
from transformers import pipeline
|
3 |
+
import fastapi
|
4 |
+
from gradio import fastapi as gr_api
|
5 |
|
|
|
6 |
generator = pipeline("text2text-generation", model="LahiruProjects/recipe-generator-flan-t5")
|
7 |
|
8 |
def generate_recipe(name, ingredients, calories, time):
|
|
|
11 |
result = generator(prompt)
|
12 |
return result[0]["generated_text"]
|
13 |
|
14 |
+
# Using gr.Blocks() for a custom interface
|
15 |
+
with gr.Blocks() as demo:
|
16 |
+
with gr.Row():
|
17 |
+
name = gr.Textbox(label="Recipe Name")
|
18 |
+
ingredients = gr.Textbox(label="Ingredients (comma-separated)")
|
19 |
+
calories = gr.Number(label="Max Calories", value=400)
|
20 |
+
time = gr.Number(label="Max Cooking Time (minutes)", value=30)
|
21 |
+
output = gr.Textbox()
|
22 |
+
demo.add(name, ingredients, calories, time, output)
|
23 |
+
|
24 |
+
# Set up FastAPI app to expose the REST API
|
25 |
+
app = fastapi.FastAPI()
|
26 |
+
app = gr_api.FastAPI(app, demo)
|
27 |
+
|
28 |
+
gr_api.add_api_route(app, "/api/predict", demo, methods=["POST"])
|
29 |
|
|