Spaces:
Runtime error
Runtime error
| from flask import Flask, request, render_template | |
| app = Flask(__name__) | |
| # Recipe suggestions based on ingredients | |
| recipes = { | |
| "paneer": [ | |
| "Paneer Butter Masala", "Palak Paneer", "Paneer Tikka", "Paneer Bhurji", "Shahi Paneer" | |
| ], | |
| "lettuce": [ | |
| "Lettuce Salad", "Lettuce Wraps", "Lettuce and Avocado Salad", "Caesar Salad" | |
| ], | |
| "carrot": [ | |
| "Carrot Halwa", "Carrot Soup", "Carrot Salad", "Carrot Cake", "Pickled Carrots" | |
| ], | |
| "broccoli": [ | |
| "Broccoli Stir Fry", "Broccoli Soup", "Broccoli Salad", "Steamed Broccoli" | |
| ], | |
| "mushrooms": [ | |
| "Mushroom Masala", "Mushroom Soup", "Mushroom Risotto", "Stuffed Mushrooms" | |
| ] | |
| } | |
| def index(): | |
| return render_template('index.html') | |
| def get_recipes(): | |
| selected_ingredients = request.form.getlist('ingredients') | |
| suggested_recipes = [] | |
| for ingredient in selected_ingredients: | |
| suggested_recipes.extend(recipes.get(ingredient, [])) | |
| return render_template('index.html', recipes=suggested_recipes) | |
| if __name__ == '__main__': | |
| # Using Gunicorn server in production | |
| from gunicorn.app.base import BaseApplication | |
| from gunicorn.six import iteritems | |
| class StandaloneApplication(BaseApplication): | |
| def __init__(self, app, options=None): | |
| self.options = options or {} | |
| self.app = app | |
| super().__init__() | |
| def load(self): | |
| return self.app | |
| def load_config(self): | |
| config = {key: value for key, value in iteritems(self.options)} | |
| for key, value in iteritems(config): | |
| self.cfg.set(key.lower(), value) | |
| options = { | |
| 'bind': '0.0.0.0:5000', # Bind to all interfaces on port 5000 | |
| 'workers': 2, # Number of worker processes | |
| } | |
| StandaloneApplication(app, options).run() | |