| import streamlit as st |
| from transformers import pipeline |
| from PIL import Image |
| import pandas as pd |
| from huggingface_hub import login |
|
|
| MIN_ACEPTABLE_SCORE = 0.1 |
| MAX_N_LABELS = 3 |
|
|
| import os |
|
|
| HF_TOKEN = os.environ.get("HF_TOKEN") |
| if HF_TOKEN: |
| login(token=HF_TOKEN) |
|
|
| TRANSLATIONS = { |
| "en-uk": { |
| "title": "Image Classification - Compare All Models", |
| "description": "🧪 Run **all** Hugging Face image classification models on a single image and compare results in an interactive table.", |
| "upload": "Upload Image", |
| "run_button": "Run All Models", |
| "results": "Results", |
| "download": "Download CSV", |
| "columns": { |
| "Model": "Model", "Category": "Category", "Label 1": "Label 1", "Score 1": "Score 1", |
| "Label 2": "Label 2", "Score 2": "Score 2", "Label 3": "Label 3", "Score 3": "Score 3", |
| }, |
| "lang_name": "English" |
| }, |
| "pt-pt": { |
| "title": "Classificação de Imagens - Compara Todos os Modelos", |
| "description": "🧪 Executa **todos os modelos** de classificação de imagens do Hugging Face numa só imagem e compara os resultados numa tabela interativa.", |
| "upload": "Carregar Imagem", |
| "run_button": "Executar Todos os Modelos", |
| "results": "Resultados", |
| "download": "Descarregar CSV", |
| "columns": { |
| "Model": "Modelo", "Category": "Categoria", "Label 1": "Label 1", "Score 1": "Score 1", |
| "Label 2": "Label 2", "Score 2": "Score 2", "Label 3": "Label 3", "Score 3": "Score 3", |
| }, |
| "lang_name": "Português (PT)" |
| }, |
| "pt-br": { |
| "title": "Classificação de Imagens - Compare Todos os Modelos", |
| "description": "🧪 Execute **todos os modelos** de classificação de imagens do Hugging Face em uma única imagem e compare os resultados em uma tabela interativa.", |
| "upload": "Carregar Imagem", |
| "run_button": "Executar Todos os Modelos", |
| "results": "Resultados", |
| "download": "Baixar CSV", |
| "columns": { |
| "Model": "Modelo", "Category": "Categoria", "Label 1": "Label 1", "Score 1": "Score 1", |
| "Label 2": "Label 2", "Score 2": "Score 2", "Label 3": "Label 3", "Score 3": "Score 3", |
| }, |
| "lang_name": "Português (BR)" |
| }, |
| "zh-cn": { |
| "title": "图像分类 - 比较所有模型", |
| "description": "🧪 在单张图像上运行**所有**Hugging Face图像分类模型,并在交互式表格中比较结果。", |
| "upload": "上传图片", |
| "run_button": "运行所有模型", |
| "results": "结果", |
| "download": "下载CSV", |
| "columns": { |
| "Model": "模型", "Category": "类别", "Label 1": "标签1", "Score 1": "分数1", |
| "Label 2": "标签2", "Score 2": "分数2", "Label 3": "标签3", "Score 3": "分数3", |
| }, |
| "lang_name": "中文" |
| }, |
| "hi": { |
| "title": "छवि वर्गीकरण - सभी मॉडल की तुलना करें", |
| "description": "🧪 एक ही छवि पर **सभी** Hugging Face छवि वर्गीकरण मॉडल चलाएं और परिणामों की एक इंटरैक्टिव टेबल में तुलना करें।", |
| "upload": "छवि अपलोड करें", |
| "run_button": "सभी मॉडल चलाएं", |
| "results": "परिणाम", |
| "download": "CSV डाउनलोड करें", |
| "columns": { |
| "Model": "मॉडल", "Category": "श्रेणी", "Label 1": "लेबल 1", "Score 1": "स्कोर 1", |
| "Label 2": "लेबल 2", "Score 2": "स्कोर 2", "Label 3": "लेबल 3", "Score 3": "स्कोर 3", |
| }, |
| "lang_name": "हिन्दी" |
| }, |
| "es": { |
| "title": "Clasificación de Imágenes - Compara Todos los Modelos", |
| "description": "🧪 Ejecuta **todos** los modelos de clasificación de imágenes de Hugging Face en una sola imagen y compara los resultados en una tabla interactiva.", |
| "upload": "Subir Imagen", |
| "run_button": "Ejecutar Todos los Modelos", |
| "results": "Resultados", |
| "download": "Descargar CSV", |
| "columns": { |
| "Model": "Modelo", "Category": "Categoría", "Label 1": "Etiqueta 1", "Score 1": "Puntuación 1", |
| "Label 2": "Etiqueta 2", "Score 2": "Puntuación 2", "Label 3": "Etiqueta 3", "Score 3": "Puntuación 3", |
| }, |
| "lang_name": "Español" |
| }, |
| "ar": { |
| "title": "تصنيف الصور - قارن جميع النماذج", |
| "description": "🧪 شغّل **جميع** نماذج تصنيف صور Hugging Face على صورة واحدة وقارن النتائج في جدول تفاعلي.", |
| "upload": "تحميل صورة", |
| "run_button": "تشغيل جميع النماذج", |
| "results": "النتائج", |
| "download": "تحميل CSV", |
| "columns": { |
| "Model": "النموذج", "Category": "الفئة", "Label 1": "التسمية 1", "Score 1": "النتيجة 1", |
| "Label 2": "التسمية 2", "Score 2": "النتيجة 2", "Label 3": "التسمية 3", "Score 3": "النتيجة 3", |
| }, |
| "lang_name": "العربية" |
| }, |
| "fr": { |
| "title": "Classification d'Images - Comparer Tous les Modèles", |
| "description": "🧪 Exécutez **tous** les modèles de classification d'images Hugging Face sur une seule image et comparez les résultats dans un tableau interactif.", |
| "upload": "Télécharger une Image", |
| "run_button": "Exécuter Tous les Modèles", |
| "results": "Résultats", |
| "download": "Télécharger CSV", |
| "columns": { |
| "Model": "Modèle", "Category": "Catégorie", "Label 1": "Étiquette 1", "Score 1": "Score 1", |
| "Label 2": "Étiquette 2", "Score 2": "Score 2", "Label 3": "Étiquette 3", "Score 3": "Score 3", |
| }, |
| "lang_name": "Français" |
| }, |
| "bn": { |
| "title": "ছবি শ্রেণীবিভাগ - সব মডেল তুলনা করুন", |
| "description": "🧪 একটি একক ছবিতে **সমস্ত** Hugging Face ছবি শ্রেণীবিভাগ মডেল চালান এবং একটি ইন্টারেক্টিভ টেবিলে ফলাফল তুলনা করুন।", |
| "upload": "ছবি আপলোড করুন", |
| "run_button": "সব মডেল চালান", |
| "results": "ফলাফল", |
| "download": "CSV ডাউনলোড করুন", |
| "columns": { |
| "Model": "মডেল", "Category": "বিভাগ", "Label 1": "লেবেল 1", "Score 1": "স্কোর 1", |
| "Label 2": "লেবেল 2", "Score 2": "স্কোর 2", "Label 3": "লেবেল 3", "Score 3": "স্কোর 3", |
| }, |
| "lang_name": "বাংলা" |
| }, |
| "ru": { |
| "title": "Классификация изображений - Сравните все модели", |
| "description": "🧪 Запустите **все** модели классификации изображений Hugging Face на одном изображении и сравните результаты в интерактивной таблице.", |
| "upload": "Загрузить изображение", |
| "run_button": "Запустить все модели", |
| "results": "Результаты", |
| "download": "Скачать CSV", |
| "columns": { |
| "Model": "Модель", "Category": "Категория", "Label 1": "Метка 1", "Score 1": "Оценка 1", |
| "Label 2": "Метка 2", "Score 2": "Оценка 2", "Label 3": "Метка 3", "Score 3": "Оценка 3", |
| }, |
| "lang_name": "Русский" |
| }, |
| "id": { |
| "title": "Klasifikasi Gambar - Bandingkan Semua Model", |
| "description": "🧪 Jalankan **semua** model klasifikasi gambar Hugging Face pada satu gambar dan bandingkan hasilnya dalam tabel interaktif.", |
| "upload": "Unggah Gambar", |
| "run_button": "Jalankan Semua Model", |
| "results": "Hasil", |
| "download": "Unduh CSV", |
| "columns": { |
| "Model": "Model", "Category": "Kategori", "Label 1": "Label 1", "Score 1": "Skor 1", |
| "Label 2": "Label 2", "Score 2": "Skor 2", "Label 3": "Label 3", "Score 3": "Skor 3", |
| }, |
| "lang_name": "Bahasa Indonesia" |
| }, |
| "de": { |
| "title": "Bildklassifizierung - Alle Modelle vergleichen", |
| "description": "🧪 Führen Sie **alle** Hugging Face Bildklassifizierungsmodelle auf einem einzigen Bild aus und vergleichen Sie die Ergebnisse in einer interaktiven Tabelle.", |
| "upload": "Bild hochladen", |
| "run_button": "Alle Modelle ausführen", |
| "results": "Ergebnisse", |
| "download": "CSV herunterladen", |
| "columns": { |
| "Model": "Modell", "Category": "Kategorie", "Label 1": "Label 1", "Score 1": "Bewertung 1", |
| "Label 2": "Label 2", "Score 2": "Bewertung 2", "Label 3": "Label 3", "Score 3": "Bewertung 3", |
| }, |
| "lang_name": "Deutsch" |
| }, |
| "nl": { |
| "title": "Afbeeldingsclassificatie - Vergelijk Alle Modellen", |
| "description": "🧪 Voer **alle** Hugging Face-afbeeldingsclassificatiemodellen uit op één enkele afbeelding en vergelijk de resultaten in een interactieve tabel.", |
| "upload": "Afbeelding uploaden", |
| "run_button": "Alle modellen uitvoeren", |
| "results": "Resultaten", |
| "download": "CSV downloaden", |
| "columns": { |
| "Model": "Model", "Category": "Categorie", "Label 1": "Label 1", "Score 1": "Score 1", |
| "Label 2": "Label 2", "Score 2": "Score 2", "Label 3": "Label 3", "Score 3": "Score 3", |
| }, |
| "lang_name": "Nederlands" |
| }, |
| "it": { |
| "title": "Classificazione Immagini - Confronta Tutti i Modelli", |
| "description": "🧪 Esegui **tutti** i modelli di classificazione immagini Hugging Face su una singola immagine e confronta i risultati in una tabella interattiva.", |
| "upload": "Carica Immagine", |
| "run_button": "Esegui Tutti i Modelli", |
| "results": "Risultati", |
| "download": "Scarica CSV", |
| "columns": { |
| "Model": "Modello", "Category": "Categoria", "Label 1": "Etichetta 1", "Score 1": "Punteggio 1", |
| "Label 2": "Etichetta 2", "Score 2": "Punteggio 2", "Label 3": "Etichetta 3", "Score 3": "Punteggio 3", |
| }, |
| "lang_name": "Italiano" |
| }, |
| "pl": { |
| "title": "Klasyfikacja Obrazów - Porównaj Wszystkie Modele", |
| "description": "🧪 Uruchom **wszystkie** modele klasyfikacji obrazów Hugging Face na jednym obrazie i porównaj wyniki w tabeli interaktywnej.", |
| "upload": "Prześlij obraz", |
| "run_button": "Uruchom wszystkie modele", |
| "results": "Wyniki", |
| "download": "Pobierz CSV", |
| "columns": { |
| "Model": "Model", "Category": "Kategoria", "Label 1": "Etykieta 1", "Score 1": "Wynik 1", |
| "Label 2": "Etykieta 2", "Score 2": "Wynik 2", "Label 3": "Etykieta 3", "Score 3": "Wynik 3", |
| }, |
| "lang_name": "Polski" |
| }, |
| "ro": { |
| "title": "Clasificarea Imaginilor - Compară Toate Modelele", |
| "description": "🧪 Rulează **toate** modelele de clasificare a imaginilor Hugging Face pe o singură imagine și compară rezultatele într-un tabel interactiv.", |
| "upload": "Încărcați imaginea", |
| "run_button": "Rulează toate modelele", |
| "results": "Rezultate", |
| "download": "Descarcă CSV", |
| "columns": { |
| "Model": "Model", "Category": "Categorie", "Label 1": "Etichetă 1", "Score 1": "Scor 1", |
| "Label 2": "Etichetă 2", "Score 2": "Scor 2", "Label 3": "Etichetă 3", "Score 3": "Scor 3", |
| }, |
| "lang_name": "Română" |
| }, |
| "hu": { |
| "title": "Képbesorolás - Összes Modell Összehasonlítása", |
| "description": "🧪 Futtassa **összes** Hugging Face képosztályozási modellt egyetlen képen, és hasonlítsa össze az eredményeket egy interaktív táblázatban.", |
| "upload": "Kép feltöltése", |
| "run_button": "Összes modell futtatása", |
| "results": "Eredmények", |
| "download": "CSV letöltése", |
| "columns": { |
| "Model": "Modell", "Category": "Kategoria", "Label 1": "Címke 1", "Score 1": "Pontszám 1", |
| "Label 2": "Címke 2", "Score 2": "Pontszám 2", "Label 3": "Címke 3", "Score 3": "Pontszám 3", |
| }, |
| "lang_name": "Magyar" |
| }, |
| "cs": { |
| "title": "Klasifikace obrázků - Porovnejte všechny modely", |
| "description": "🧪 Spusťte **všechny** modely klasifikace obrázků Hugging Face na jednom obrázku a porovnejte výsledky v interaktivní tabulce.", |
| "upload": "Nahrát obrázek", |
| "run_button": "Spustit všechny modely", |
| "results": "Výsledky", |
| "download": "Stáhnout CSV", |
| "columns": { |
| "Model": "Model", "Category": "Kategorie", "Label 1": "Štítek 1", "Score 1": "Skóre 1", |
| "Label 2": "Štítek 2", "Score 2": "Skóre 2", "Label 3": "Štítek 3", "Score 3": "Skóre 3", |
| }, |
| "lang_name": "Čeština" |
| }, |
| "sk": { |
| "title": "Klasifikácia obrázkov - Porovnajte všetky modely", |
| "description": "🧪 Spustite **všetky** modely klasifikácie obrázkov Hugging Face na jednom obrázku a porovnajte výsledky v interaktívnej tabuľke.", |
| "upload": "Nahrať obrázok", |
| "run_button": "Spustiť všetky modely", |
| "results": "Výsledky", |
| "download": "Stiahnuť CSV", |
| "columns": { |
| "Model": "Model", "Category": "Kategória", "Label 1": "Štítok 1", "Score 1": "Skóre 1", |
| "Label 2": "Štítok 2", "Score 2": "Skóre 2", "Label 3": "Štítok 3", "Score 3": "Skóre 3", |
| }, |
| "lang_name": "Slovenčina" |
| }, |
| "sl": { |
| "title": "Klasifikacija slik - Primerjajte vse modele", |
| "description": "🧪 Zaženite **vse** modele klasifikacije slik Hugging Face na eni sliki in primerjajte rezultate v interaktivni tabeli.", |
| "upload": "Naloži sliko", |
| "run_button": "Zaženi vse modele", |
| "results": "Rezultati", |
| "download": "Prenesi CSV", |
| "columns": { |
| "Model": "Model", "Category": "Kategorije", "Label 1": "Oznaka 1", "Score 1": "Točke 1", |
| "Label 2": "Oznaka 2", "Score 2": "Točke 2", "Label 3": "Oznaka 3", "Score 3": "Točke 3", |
| }, |
| "lang_name": "Slovenščina" |
| }, |
| "da": { |
| "title": "Billedklassifikation - Sammenlign Alle Modeller", |
| "description": "🧪 Kør **alle** Hugging Face billedklassifikationsmodeller på et enkelt billede og sammenlign resultaterne i en interaktiv tabel.", |
| "upload": "Upload billede", |
| "run_button": "Kør alle modeller", |
| "results": "Resultater", |
| "download": "Download CSV", |
| "columns": { |
| "Model": "Model", "Category": "Kategori", "Label 1": "Etiket 1", "Score 1": "Point 1", |
| "Label 2": "Etiket 2", "Score 2": "Point 2", "Label 3": "Etiket 3", "Score 3": "Point 3", |
| }, |
| "lang_name": "Dansk" |
| }, |
| "sv": { |
| "title": "Bildklassificering - Jämför Alla Modeller", |
| "description": "🧪 Kör **alla** Hugging Face bildklassificeringsmodeller på en enda bild och jämför resultaten i en interaktiv tabell.", |
| "upload": "Ladda upp bild", |
| "run_button": "Kör alla modeller", |
| "results": "Resultat", |
| "download": "Ladda ner CSV", |
| "columns": { |
| "Model": "Modell", "Category": "Kategori", "Label 1": "Etikett 1", "Score 1": "Poäng 1", |
| "Label 2": "Etikett 2", "Score 2": "Poäng 2", "Label 3": "Etikett 3", "Score 3": "Poäng 3", |
| }, |
| "lang_name": "Svenska" |
| }, |
| "fi": { |
| "title": "Kuvaluokittelu - Vertaa Kaikkia Malleja", |
| "description": "🧪 Suorita **kaikki** Hugging Face -kuvaluokittelumallit yhdellä kuvalla ja vertaa tuloksia vuorovaikutteisessa taulukossa.", |
| "upload": "Lataa kuva", |
| "run_button": "Suorita kaikki mallit", |
| "results": "Tulokset", |
| "download": "Lataa CSV", |
| "columns": { |
| "Model": "Malli", "Category": "Luokka", "Label 1": "Tunniste 1", "Score 1": "Pisteet 1", |
| "Label 2": "Tunniste 2", "Score 2": "Pisteet 2", "Label 3": "Tunniste 3", "Score 3": "Pisteet 3", |
| }, |
| "lang_name": "Suomi" |
| }, |
| "el": { |
| "title": "Ταξινόμηση Εικόνων - Σύγκριση Όλων των Μοντέλων", |
| "description": "🧪 Εκτελέστε **όλα** τα μοντέλα ταξινόμησης εικόνων του Hugging Face σε μία εικόνα και συγκρίνετε τα αποτελέσματα σε έναν διαδραστικό πίνακα.", |
| "upload": "Μεταφόρτωση εικόνας", |
| "run_button": "Εκτέλεση όλων των μοντέλων", |
| "results": "Αποτελέσματα", |
| "download": "Λήψη CSV", |
| "columns": { |
| "Model": "Μοντέλο", "Category": "Κατηγορία", "Label 1": "Ετικέτα 1", "Score 1": "Βαθμολογία 1", |
| "Label 2": "Ετικέτα 2", "Score 2": "Βαθμολογία 2", "Label 3": "Ετικέτα 3", "Score 3": "Βαθμολογία 3", |
| }, |
| "lang_name": "Ελληνικά" |
| }, |
| "bg": { |
| "title": "Класификация на изображения - Сравнете всички модели", |
| "description": "🧪 Стартирайте **всички** модели за класификация на изображения от Hugging Face на едно изображение и сравнете резултатите в интерактивна таблица.", |
| "upload": "Качете изображение", |
| "run_button": "Стартирайте всички модели", |
| "results": "Резултати", |
| "download": "Изтеглете CSV", |
| "columns": { |
| "Model": "Модел", "Category": "Категория", "Label 1": "Етикет 1", "Score 1": "Резултат 1", |
| "Label 2": "Етикет 2", "Score 2": "Резултат 2", "Label 3": "Етикет 3", "Score 3": "Резултат 3", |
| }, |
| "lang_name": "Български" |
| }, |
| "lv": { |
| "title": "Attēlu klasifikācija - Salīdziniet visus modeļus", |
| "description": "🧪 Palaidiet **visus** Hugging Face attēlu klasifikācijas modeļus uz viena attēla un salīdziniet rezultātus interaktīvā tabulā.", |
| "upload": "Augšupielādēt attēlu", |
| "run_button": "Palaist visus modeļus", |
| "results": "Rezultāti", |
| "download": "Lejupielādēt CSV", |
| "columns": { |
| "Model": "Modelis", "Category": "Kategorijas", "Label 1": "Etiķete 1", "Score 1": "Rezultāts 1", |
| "Label 2": "Etiķete 2", "Score 2": "Rezultāts 2", "Label 3": "Etiķete 3", "Score 3": "Rezultāts 3", |
| }, |
| "lang_name": "Latviešu" |
| }, |
| "lt": { |
| "title": "Vaizdų klasifikavimas - Palyginkite visus modelius", |
| "description": "🧪 Paleiskite **visus** Hugging Face vaizdų klasifikavimo modelius vienoje nuotraukoje ir palyginkite rezultatus interaktyvioje lentelėje.", |
| "upload": "Įkelti vaizdą", |
| "run_button": "Paleisti visus modelius", |
| "results": "Rezultatai", |
| "download": "Atsisiųsti CSV", |
| "columns": { |
| "Model": "Modelis", "Category": "Kategorijos", "Label 1": "Etiketė 1", "Score 1": "Rezultatas 1", |
| "Label 2": "Etiketė 2", "Score 2": "Rezultatas 2", "Label 3": "Etiketė 3", "Score 3": "Rezultatas 3", |
| }, |
| "lang_name": "Lietuvių" |
| }, |
| "et": { |
| "title": "Pildiklassifikatsioon - Võrdle kõiki mudeleid", |
| "description": "🧪 Käivitage **kõik** Hugging Face pildiklassifikatsiooni mudelid ühel pildil ja võrrelge tulemusi interaktiivses tabelis.", |
| "upload": "Laadi pilt üles", |
| "run_button": "Käivita kõik mudelid", |
| "results": "Tulemused", |
| "download": "Laadi CSV alla", |
| "columns": { |
| "Model": "Mudel", "Category": "Kategooria", "Label 1": "Silt 1", "Score 1": "Skoor 1", |
| "Label 2": "Silt 2", "Score 2": "Skoor 2", "Label 3": "Silt 3", "Score 3": "Skoor 3", |
| }, |
| "lang_name": "Eesti" |
| }, |
| "ga": { |
| "title": "Rangú Imagacha - Déan Comparáid idir na Samhlaithe go léir", |
| "description": "🧪 Rith **gach** samhail rangaithe imeagacha Hugging Face ar aon íomhá amháin agus déan comparáid ar thorthaí i dtábla idirghníomhach.", |
| "upload": "Uaslódáil Íomhá", |
| "run_button": "Rith gach Samhail", |
| "results": "Torthaí", |
| "download": "Íosluchtaigh CSV", |
| "columns": { |
| "Model": "Samhail", "Category": "Catagóir", "Label 1": "Lipéad 1", "Score 1": "Scór 1", |
| "Label 2": "Lipéad 2", "Score 2": "Scór 2", "Label 3": "Lipéad 3", "Score 3": "Scór 3", |
| }, |
| "lang_name": "Gaeilge" |
| }, |
| "mt": { |
| "title": "Klassifikazzjoni tal-Immaġnijiet - Qabbel il-Mudelli kollha", |
| "description": "🧪 ŻRuns **il-mudelli kollha** ta' klassifikazzjoni tal-immaġnijiet ta' Hugging Face fuq immaġni waħda u qabbel ir-rizultati f'tabella interattiva.", |
| "upload": "Upload Image", |
| "run_button": "Run All Models", |
| "results": "Risultati", |
| "download": "Download CSV", |
| "columns": { |
| "Model": "Mudell", "Category": "Kategoriji", "Label 1": "Tikketta 1", "Score 1": "Punteġġ 1", |
| "Label 2": "Tikketta 2", "Score 2": "Punteġġ 2", "Label 3": "Tikketta 3", "Score 3": "Punteġġ 3", |
| }, |
| "lang_name": "Malti" |
| }, |
| "hr": { |
| "title": "Klasifikacija slika - Usporedite sve modele", |
| "description": "🧪 Pokrenite **sve** modele klasifikacije slika Hugging Face na jednoj slici i usporedite rezultate u interaktivnoj tablici.", |
| "upload": "Prenesi sliku", |
| "run_button": "Pokreni sve modele", |
| "results": "Rezultati", |
| "download": "Preuzmi CSV", |
| "columns": { |
| "Model": "Model", "Category": "Kategorije", "Label 1": "Oznaka 1", "Score 1": "Rezultat 1", |
| "Label 2": "Oznaka 2", "Score 2": "Rezultat 2", "Label 3": "Oznaka 3", "Score 3": "Rezultat 3", |
| }, |
| "lang_name": "Hrvatski" |
| }, |
| } |
|
|
| lang = st.selectbox("Language / Idioma", list(TRANSLATIONS.keys()), format_func=lambda x: TRANSLATIONS[x]["lang_name"]) |
| t = TRANSLATIONS[lang] |
|
|
| MODELS = [ |
| ("google/vit-base-patch16-224", "General Image Classification"), |
| ("microsoft/resnet-50", "General Image Classification"), |
| ("microsoft/resnet-18", "General Image Classification"), |
| ("microsoft/resnet-34", "General Image Classification"), |
| ("microsoft/resnet-101", "General Image Classification"), |
| ("microsoft/swin-tiny-patch4-window7-224", "General Image Classification"), |
| ("microsoft/swinv2-base-patch4-window16-256", "General Image Classification"), |
| ("facebook/convnext-large-224", "General Image Classification"), |
| ("facebook/convnext-base-224-22k-1k", "General Image Classification"), |
| ("facebook/convnext-tiny-224", "General Image Classification"), |
| ("timm/resnet50.a1_in1k", "General Image Classification"), |
| ("timm/tf_efficientnetv2_s.in21k", "General Image Classification"), |
| ("timm/convnext_tiny.fb_in22k", "General Image Classification"), |
| ("google/vit-base-patch16-224-in21k", "General Image Classification"), |
| ("facebook/deit-base-distilled-patch16-224", "General Image Classification"), |
| ("WinKawaks/vit-tiny-patch16-224", "General Image Classification"), |
|
|
| ("nateraw/vit-age-classifier", "Age Classification"), |
|
|
| ("Falconsai/nsfw_image_detection", "NSFW Detection"), |
| ("carbon225/vit-base-patch16-224-hentai", "NSFW Detection"), |
|
|
| ("cafeai/cafe_aesthetic", "Aesthetic/Art Classification"), |
|
|
| ("trpakov/vit-face-expression", "Face/Emotion Classification"), |
| ("RickyIG/emotion_face_image_classification", "Face/Emotion Classification"), |
| ("rizvandwiki/gender-classification", "Face/Emotion Classification"), |
|
|
| ("Ateeqq/ai-vs-human-image-detector", "AI vs Human Detection"), |
| ("umm-maybe/AI-image-detector", "AI vs Human Detection"), |
|
|
| ("DunnBC22/vit-base-patch16-224-in21k_Human_Activity_Recognition", "Human Activity Recognition"), |
|
|
| ("andupets/real-estate-image-classification", "Real Estate"), |
|
|
| ("lamnt2008/car_brands_classification", "Car Classification"), |
|
|
| ("docling-project/DocumentFigureClassifier-v2.5", "Document Classification"), |
|
|
| ("timm/efficientnet_b0.ra_in1k", "EfficientNet"), |
| ("timm/mobilenetv3_large_100.ra_in1k", "EfficientNet"), |
| ("timm/mobilenetv3_small_100.lamb_in1k", "EfficientNet"), |
| ] |
|
|
| def classify(image, model_name): |
| classifier = pipeline("image-classification", model=model_name) |
| result = classifier(image) |
| return result |
|
|
| def format_results(results): |
| formatted = [] |
| for r in results[:MAX_N_LABELS]: |
| if r['score'] >= MIN_ACEPTABLE_SCORE: |
| formatted.append({ |
| "label": r['label'], |
| "score": f"{r['score']:.2%}" |
| }) |
| while len(formatted) < 3: |
| formatted.append({"label": "-", "score": "-"}) |
| return formatted |
|
|
| def main(): |
| st.title(t["title"]) |
| st.markdown(t["description"]) |
| |
| bmc_link = "https://www.buymeacoffee.com/nuno.tome" |
| image_url = "https://i.giphy.com/RETzc1mj7HpZPuNf3e.webp" |
| image_link_markdown = f"[]({bmc_link})" |
| st.markdown(image_link_markdown, unsafe_allow_html=True) |
| |
| input_image = st.file_uploader(t["upload"]) |
|
|
| if input_image is not None: |
| image_to_classify = Image.open(input_image) |
| st.image(image_to_classify, caption="Uploaded Image", use_column_width=True) |
| |
| if st.button(t["run_button"], type="primary"): |
| results_data = [] |
| progress_bar = st.progress(0) |
| status_text = st.empty() |
| |
| for i, (model_name, category) in enumerate(MODELS): |
| status_text.text(f"Running model {i+1}/{len(MODELS)}: {model_name}") |
| try: |
| classification_result = classify(image_to_classify, model_name) |
| formatted = format_results(classification_result) |
| results_data.append({ |
| "Model": model_name, |
| "Category": category, |
| "Label 1": formatted[0]["label"], |
| "Score 1": formatted[0]["score"], |
| "Label 2": formatted[1]["label"], |
| "Score 2": formatted[1]["score"], |
| "Label 3": formatted[2]["label"], |
| "Score 3": formatted[2]["score"], |
| }) |
| except Exception as e: |
| results_data.append({ |
| "Model": model_name, |
| "Category": category, |
| "Label 1": f"Error: {str(e)[:50]}", |
| "Score 1": "-", |
| "Label 2": "-", |
| "Score 2": "-", |
| "Label 3": "-", |
| "Score 3": "-", |
| }) |
| progress_bar.progress((i + 1) / len(MODELS)) |
| |
| status_text.text("Done!") |
| |
| if results_data: |
| df = pd.DataFrame(results_data) |
| df = df.rename(columns=t["columns"]) |
| st.subheader(f"{t['results']} ({len(results_data)} models)") |
| |
| st.markdown(""" |
| <style> |
| .dataframe {font-size: 12px;} |
| </style> |
| """, unsafe_allow_html=True) |
| |
| st.dataframe( |
| df, |
| use_container_width=True, |
| hide_index=True, |
| column_config={ |
| t["columns"]["Model"]: st.column_config.TextColumn(t["columns"]["Model"], width="medium"), |
| t["columns"]["Category"]: st.column_config.TextColumn(t["columns"]["Category"], width="small"), |
| t["columns"]["Label 1"]: st.column_config.TextColumn(t["columns"]["Label 1"], width="medium"), |
| t["columns"]["Score 1"]: st.column_config.TextColumn(t["columns"]["Score 1"], width="small"), |
| t["columns"]["Label 2"]: st.column_config.TextColumn(t["columns"]["Label 2"], width="medium"), |
| t["columns"]["Score 2"]: st.column_config.TextColumn(t["columns"]["Score 2"], width="small"), |
| t["columns"]["Label 3"]: st.column_config.TextColumn(t["columns"]["Label 3"], width="medium"), |
| t["columns"]["Score 3"]: st.column_config.TextColumn(t["columns"]["Score 3"], width="small"), |
| } |
| ) |
| |
| csv = df.to_csv(index=False).encode('utf-8') |
| st.download_button( |
| t["download"], |
| csv, |
| "classification_results.csv", |
| "text/csv", |
| key='download-csv' |
| ) |
|
|
|
|
| if __name__ == "__main__": |
| main() |