ankz22 commited on
Commit
c3b16a7
·
1 Parent(s): 52f9526

Add application file

Browse files
Files changed (2) hide show
  1. app.py +15 -11
  2. 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
- yield "🔄 Traitement de l'image... Veuillez patienter."
 
35
 
36
- # Augmentation
37
- image_aug = augment(image)
38
 
39
- # Classification
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
- yield f"### 🥕 Ingrédients détectés :\n{ingredient_str}\n\n### 🍽️ Recette générée :\n{recipe}"
 
 
 
 
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