LahiruProjects commited on
Commit
97f00ad
Β·
verified Β·
1 Parent(s): 71920ff

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +17 -15
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
- # Gradio interface
14
- iface = gr.Interface(
15
- fn=generate_recipe,
16
- inputs=[
17
- gr.Textbox(label="Recipe Name"),
18
- gr.Textbox(label="Ingredients (comma-separated)"),
19
- gr.Number(label="Max Calories", value=400),
20
- gr.Number(label="Max Cooking Time (minutes)", value=30)
21
- ],
22
- outputs="text",
23
- title="🍳 Recipe Generator (FLAN-T5)",
24
- description="Generate a step-by-step recipe based on ingredients, calorie limit, and time"
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