Spaces:
Sleeping
Sleeping
Add application file
Browse files- app.py +15 -11
- requirements.txt +5 -5
app.py
CHANGED
|
@@ -31,20 +31,24 @@ augment = transforms.Compose([
|
|
| 31 |
|
| 32 |
# FONCTION PRINCIPALE
|
| 33 |
def generate_recipe(image: Image.Image):
|
| 34 |
-
|
|
|
|
| 35 |
|
| 36 |
-
|
| 37 |
-
image_aug = augment(image)
|
| 38 |
|
| 39 |
-
|
| 40 |
-
|
| 41 |
-
|
| 42 |
-
|
| 43 |
|
| 44 |
-
|
| 45 |
-
|
| 46 |
-
|
| 47 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 48 |
|
| 49 |
# INTERFACE
|
| 50 |
interface = gr.Interface(
|
|
|
|
| 31 |
|
| 32 |
# FONCTION PRINCIPALE
|
| 33 |
def generate_recipe(image: Image.Image):
|
| 34 |
+
try:
|
| 35 |
+
yield "🔄 Traitement de l'image..."
|
| 36 |
|
| 37 |
+
image_aug = image
|
|
|
|
| 38 |
|
| 39 |
+
yield "📸 Classification en cours..."
|
| 40 |
+
results = ingredient_classifier(image_aug)
|
| 41 |
+
ingredients = [res["label"] for res in results]
|
| 42 |
+
ingredient_str = ", ".join(ingredients)
|
| 43 |
|
| 44 |
+
yield f"🥕 Ingrédients détectés : {ingredient_str}\n\n🍳 Génération de la recette..."
|
| 45 |
+
prompt = f"Ingredients: {ingredient_str}. Recipe:"
|
| 46 |
+
recipe = recipe_generator(prompt, max_new_tokens=256, do_sample=True)[0]["generated_text"]
|
| 47 |
+
|
| 48 |
+
yield f"### 🥕 Ingrédients détectés :\n{ingredient_str}\n\n### 🍽️ Recette générée :\n{recipe}"
|
| 49 |
+
|
| 50 |
+
except Exception as e:
|
| 51 |
+
yield f"❌ Une erreur est survenue : {str(e)}"
|
| 52 |
|
| 53 |
# INTERFACE
|
| 54 |
interface = gr.Interface(
|
requirements.txt
CHANGED
|
@@ -1,5 +1,5 @@
|
|
| 1 |
-
gradio
|
| 2 |
-
transformers
|
| 3 |
-
torch
|
| 4 |
-
torchvision
|
| 5 |
-
pillow
|
|
|
|
| 1 |
+
gradio==4.25.0
|
| 2 |
+
transformers==4.40.1
|
| 3 |
+
torch>=2.1.0
|
| 4 |
+
torchvision>=0.16.0
|
| 5 |
+
pillow>=10.0.0
|