Spaces:
Build error
Build error
Update app.py
Browse files
app.py
CHANGED
@@ -3,23 +3,23 @@ import google.generativeai as genai
|
|
3 |
from yolov5 import YOLOv5
|
4 |
from PIL import Image
|
5 |
|
6 |
-
#
|
7 |
genai.configure(api_key="AIzaSyB_Hnl_77gd1I8xs6iuLqKIoGHgsZMXm1M")
|
8 |
|
9 |
-
#
|
10 |
gemini_model = genai.GenerativeModel('gemini-pro')
|
11 |
|
12 |
-
#
|
13 |
yolo_model_path = "yolov5s.pt"
|
14 |
yolo_model = YOLOv5(yolo_model_path, device="cpu")
|
15 |
|
16 |
-
#
|
17 |
def detect_ingredients(image):
|
18 |
results = yolo_model.predict(image)
|
19 |
ingredients = results.pandas().xyxy[0]['name'].tolist()
|
20 |
return ingredients
|
21 |
|
22 |
-
#
|
23 |
def generate_recipe(ingredients):
|
24 |
# Ajoutez une indication dans le prompt pour générer la réponse en français
|
25 |
prompt = f"""
|
@@ -55,8 +55,6 @@ def generate_recipe(ingredients):
|
|
55 |
return response.text
|
56 |
|
57 |
|
58 |
-
|
59 |
-
|
60 |
# Interface Gradio
|
61 |
def process_image(image):
|
62 |
# Ouvrir l'image depuis le chemin fourni
|
@@ -74,7 +72,7 @@ iface = gr.Interface(
|
|
74 |
description="Téléchargez une image d'ingrédients pour générer une recette.",
|
75 |
)
|
76 |
|
77 |
-
#
|
78 |
if __name__ == "__main__":
|
79 |
iface.launch()
|
80 |
|
|
|
3 |
from yolov5 import YOLOv5
|
4 |
from PIL import Image
|
5 |
|
6 |
+
# Clé API
|
7 |
genai.configure(api_key="AIzaSyB_Hnl_77gd1I8xs6iuLqKIoGHgsZMXm1M")
|
8 |
|
9 |
+
# Le modèle Gemini Pro
|
10 |
gemini_model = genai.GenerativeModel('gemini-pro')
|
11 |
|
12 |
+
# Le modèle de détection YOLOv5
|
13 |
yolo_model_path = "yolov5s.pt"
|
14 |
yolo_model = YOLOv5(yolo_model_path, device="cpu")
|
15 |
|
16 |
+
# Détection d'ingrédients
|
17 |
def detect_ingredients(image):
|
18 |
results = yolo_model.predict(image)
|
19 |
ingredients = results.pandas().xyxy[0]['name'].tolist()
|
20 |
return ingredients
|
21 |
|
22 |
+
# Prompt de génération de recettes (Mistral AI)
|
23 |
def generate_recipe(ingredients):
|
24 |
# Ajoutez une indication dans le prompt pour générer la réponse en français
|
25 |
prompt = f"""
|
|
|
55 |
return response.text
|
56 |
|
57 |
|
|
|
|
|
58 |
# Interface Gradio
|
59 |
def process_image(image):
|
60 |
# Ouvrir l'image depuis le chemin fourni
|
|
|
72 |
description="Téléchargez une image d'ingrédients pour générer une recette.",
|
73 |
)
|
74 |
|
75 |
+
# Pour lancer l'application
|
76 |
if __name__ == "__main__":
|
77 |
iface.launch()
|
78 |
|