Download app.py from chrisis2/testmodelprojekt: direct link, hf CLI and curl.
- Browser
- Download file 2.04 kB
-
https://huggingface.co/chrisis2/testmodelprojekt/resolve/main/app.py
- Command line
-
hf download hf://chrisis2/testmodelprojekt/app.py
-
curl -L -o app.py https://huggingface.co/chrisis2/testmodelprojekt/resolve/main/app.py
2.04 kB
| #! pip install gradio | |
| import gradio as gr | |
| from transformers import pipeline | |
| # Lade beide Modelle | |
| vit_classifier = pipeline("image-classification", model="chrisis2/vit-food-classification-chrisis2") # Ersetze mit deinem Modell | |
| clip_detector = pipeline(model="openai/clip-vit-large-patch14", task="zero-shot-image-classification") | |
| # Verwende deine Food-Labels | |
| food_labels = [ | |
| "Baked Potato", "Crispy Chicken", "Donut", "Fries", "Hot Dog", "Sandwich", "Taco", "Taquito", | |
| "apple_pie", "burger", "butter_naan", "chai", "chapati", "cheesecake", "chicken_curry", | |
| "chole_bhature", "dal_makhani", "dhokla", "fried_rice", "ice_cream", "idli", "jalebi", | |
| "kaathi_rolls", "kadai_paneer", "kulfi", "masala_dosa", "momos", "omelette", "paani_puri", | |
| "pakode", "pav_bhaji", "pizza", "samosa", "sushi" | |
| ] | |
| def classify_food(image): | |
| # Klassifiziere mit deinem trainierten Modell | |
| vit_results = vit_classifier(image) | |
| vit_output = {result['label']: result['score'] for result in vit_results} | |
| # Klassifiziere mit CLIP Zero-Shot | |
| clip_results = clip_detector(image, candidate_labels=food_labels) | |
| clip_output = {result['label']: result['score'] for result in clip_results} | |
| return {"Trainiertes ViT-Modell": vit_output, "CLIP Zero-Shot": clip_output} | |
| # Füge Beispielbilder aus deinem Dataset hinzu | |
| example_images = [ | |
| ["gradio-food-app/example_images/burger.jpg.jpg"], | |
| ["gradio-food-app/example_images/burger.jpg.jpg"], | |
| ["gradio-food-app/example_images/burger.jpg.jpg"], | |
| ["gradio-food-app/example_images/pizza.jpg.jpg"], | |
| ["gradio-food-app/example_images/sushi.jpg.jpg"], | |
| # Füge weitere Beispiele hinzu | |
| ] | |
| # Erstelle die Gradio-Oberfläche | |
| iface = gr.Interface( | |
| fn=classify_food, | |
| inputs=gr.Image(type="filepath"), | |
| outputs=gr.JSON(), | |
| title="Food Classification Vergleich", | |
| description="Lade ein Bild eines Lebensmittels hoch und vergleiche die Ergebnisse eines trainierten ViT-Modells mit einem Zero-Shot CLIP-Modell.", | |
| examples=example_images | |
| ) | |
| iface.launch() | |