CazC commited on
Commit
a094d9f
·
1 Parent(s): cbf8e94

chore: Add recipe generation and formatting functions

Browse files
Files changed (2) hide show
  1. .gitignore +1 -0
  2. app.py +69 -0
.gitignore ADDED
@@ -0,0 +1 @@
 
 
1
+ structuredOutputs.py
app.py ADDED
@@ -0,0 +1,69 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ import json
3
+ from pydantic import BaseModel
4
+ from typing import List
5
+
6
+ # Define the Pydantic models
7
+ class Ingredient(BaseModel):
8
+ quantity: str
9
+ unit: str
10
+ name: str
11
+
12
+ class Steps(BaseModel):
13
+ stepNumber: int
14
+ instruction: str
15
+
16
+ class ProduceRecipe(BaseModel):
17
+ mealName: str
18
+ ingredients: List[Ingredient]
19
+ steps: List[Steps]
20
+
21
+ # This is a placeholder for your actual function
22
+ def generate_recipe(meal_name: str, calories: int, meal_time: str) -> ProduceRecipe:
23
+ # This is where you'll implement your recipe generation logic
24
+ # For now, we'll return a dummy recipe
25
+ dummy_recipe = {
26
+ "mealName": meal_name,
27
+ "ingredients": [
28
+ {"quantity": "2", "unit": "large", "name": "eggs"},
29
+ {"quantity": "1/4", "unit": "cup", "name": "onion, diced"}
30
+ ],
31
+ "steps": [
32
+ {"stepNumber": 1, "instruction": "Crack the eggs into a bowl."},
33
+ {"stepNumber": 2, "instruction": "Whisk the eggs and add diced onions."}
34
+ ]
35
+ }
36
+ return ProduceRecipe(**dummy_recipe)
37
+
38
+ def format_recipe(recipe: ProduceRecipe) -> str:
39
+ formatted = f"<h2>{recipe.mealName}</h2>\n\n"
40
+
41
+ formatted += "<h3>Ingredients:</h3>\n<ul>\n"
42
+ for ingredient in recipe.ingredients:
43
+ formatted += f"<li>{ingredient.quantity} {ingredient.unit} {ingredient.name}</li>\n"
44
+ formatted += "</ul>\n\n"
45
+
46
+ formatted += "<h3>Instructions:</h3>\n<ol>\n"
47
+ for step in recipe.steps:
48
+ formatted += f"<li>{step.instruction}</li>\n"
49
+ formatted += "</ol>"
50
+
51
+ return formatted
52
+
53
+ def recipe_interface(meal_name: str, calories: int, meal_time: str) -> str:
54
+ recipe = generate_recipe(meal_name, calories, meal_time)
55
+ return format_recipe(recipe)
56
+
57
+ iface = gr.Interface(
58
+ fn=recipe_interface,
59
+ inputs=[
60
+ gr.Textbox(label="Meal Name"),
61
+ gr.Number(label="Calories"),
62
+ gr.Dropdown(["breakfast", "lunch", "dinner"], label="Meal Time")
63
+ ],
64
+ outputs=gr.HTML(label="Recipe"),
65
+ title="Meal Recipe Generator",
66
+ description="Generate a recipe based on meal name, calories, and meal time."
67
+ )
68
+
69
+ iface.launch()