Update main.py

This commit is contained in:
HarshvardhanChandel 2025-03-31 07:32:19 +00:00
parent 725342187c
commit 07b55051e6

12
main.py
View file

@ -1,10 +1,12 @@
from groq_module import groq_module_fun, chat_with_groq from groq_module import groq_module_fun, chat_with_groq
from helpers import jpeg_to_base64, extract_json_to_dict from helpers import jpeg_to_base64, extract_json_to_dict
from flask import Flask, request, jsonify from flask import Flask, request, jsonify
from flask_cors import CORS # Import CORS
import json import json
import os import os
app = Flask(__name__) app = Flask(__name__)
CORS(app) # Enable CORS for all routes
@app.route('/recipe-maker', methods=['POST']) @app.route('/recipe-maker', methods=['POST'])
def recipe_maker(): def recipe_maker():
@ -14,14 +16,12 @@ def recipe_maker():
query = data.get('query') query = data.get('query')
prompt = f''' based on the following query: prompt = f''' based on the following query:
query: {query} query: {query}
generate the recipe of the best 5 dishes in the following JSON format: generate the recipe of the best 5 dishes in the following JSON format:
{{ {{
"message": "<message response>" "message": "<message response>",
"Recipe":{{ "Recipe":{{
"dish1": {{ "dish1": {{
"name": "<dish name>", "name": "<dish name>",
@ -49,7 +49,6 @@ def recipe_maker():
"instructions": "<dish instructions>" "instructions": "<dish instructions>"
}} }}
}} }}
}} }}
''' '''
@ -57,8 +56,6 @@ def recipe_maker():
print(response) print(response)
recipe = extract_json_to_dict(response) recipe = extract_json_to_dict(response)
result = { result = {
"recipe": recipe, "recipe": recipe,
"query": query, "query": query,
@ -135,8 +132,6 @@ def meal_diet_plan():
print(response) print(response)
week_diet_plan = extract_json_to_dict(response) week_diet_plan = extract_json_to_dict(response)
result = { result = {
"meal_diet_plan": week_diet_plan, "meal_diet_plan": week_diet_plan,
"weight": weight, "weight": weight,
@ -197,4 +192,3 @@ def food_scan():
if __name__ == '__main__': if __name__ == '__main__':
app.run(host='0.0.0.0', port=5000, debug=True) app.run(host='0.0.0.0', port=5000, debug=True)