File size: 4,739 Bytes
5370228 ea291d0 5370228 dfc18ca cc0b667 dfc18ca 5370228 cc0b667 5370228 9a170fd 5370228 4d86b16 9a170fd 4d86b16 5370228 ea291d0 5370228 dfc18ca 5370228 9a170fd dfc18ca cca14f9 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 |
import gradio as gr
from services.search_service import FoodSearchService
class GradioUI:
def __init__(self):
self.food_service = FoodSearchService()
def search_food_products(self, query: str, max_results: int) -> str:
"""
Recherche des produits alimentaires dans la base de données OpenFoodFacts.
Cette fonction effectue une recherche intelligente
de produits alimentaires en analysant la requête utilisateur avec Mistral AI
pour extraire le nom du produit et la marque, puis interroge la base DuckDB.
Args:
query (str): Terme de recherche saisi par l'utilisateur.
Peut contenir un nom de produit, une marque, ou une combinaison.
Exemples: "pepito", "biscuits lu", "pizza picard", "yaourt danone"
max_results (int): Nombre maximum de résultats à retourner.
Doit être compris entre 1 et 20.
Returns:
str: Résultats de recherche formatés en Markdown contenant :
- Informations nutritionnelles (Nutri-Score, Eco-Score, NOVA)
- Liste des ingrédients et additifs
- Allergènes potentiels
- Analyse détaillée par Mistral AI
"""
return self.food_service.search_and_format_products(query, max_results)
def create_interface(self):
custom_css = """
.footer {
margin-top: 40px;
padding: 20px;
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
border-radius: 12px;
text-align: center;
color: white;
}
.footer h3 {
margin: 0 0 10px 0;
font-size: 18px;
font-weight: 600;
}
.footer p {
margin: 5px 0;
font-size: 14px;
opacity: 0.9;
}
.footer a {
color: #ffd700;
text-decoration: none;
font-weight: 500;
}
.footer a:hover {
text-decoration: underline;
}
"""
with gr.Blocks(title="🤖 Healthify me", theme=gr.themes.Soft(), css=custom_css) as demo:
# En-tête
gr.Markdown("""
# 🤖 Healthify me
""")
with gr.Row():
with gr.Column(scale=3):
search_input = gr.Textbox(
label="🔍 Search for product",
placeholder="Ex: pepito, biscuits lu, pizza picard, yaourt danone..."
)
with gr.Column(scale=1):
max_results = gr.Slider(
minimum=1,
maximum=20,
value=5,
step=1,
label="📊 Number of results",
info="How many results ?"
)
search_btn = gr.Button("🤖 Search", variant="primary", size="lg")
search_output = gr.Markdown("""
### Welcome to Healthify me! This interface allows you to search for food products and obtain detailed nutritional information.
**How to use:**
- Enter the name of a product (e.g., "Nutella", "pizza Picard", "Fuzetea drink")
- Select the number of results you want
- Click "Search"
**Available information:**
- Nutri-Score and NOVA
- Complete list of ingredients
- Allergens present
- Detailed nutritional values
*Ready to start your search...*
""")
search_btn.click(
fn=self.search_food_products,
inputs=[search_input, max_results],
outputs=[search_output]
)
gr.HTML("""
<div class="footer">
<p>Healthify Me</p>
<p style="margin-top: 15px; font-size: 12px;">
Made with 💙 by Joe Dac. Get in touch on <a href="https://www.linkedin.com/in/jonathan-ribeiro-da-costa/">LinkedIn</a>
</p>
</div>
""")
return demo |