feat: add pt-pt and en-uk language support with sidebar selector
Browse files
app.py
CHANGED
|
@@ -13,6 +13,28 @@ HF_TOKEN = os.environ.get("HF_TOKEN")
|
|
| 13 |
if HF_TOKEN:
|
| 14 |
login(token=HF_TOKEN)
|
| 15 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 16 |
MODELS = [
|
| 17 |
("google/vit-base-patch16-224", "General Image Classification"),
|
| 18 |
("microsoft/resnet-50", "General Image Classification"),
|
|
@@ -76,22 +98,21 @@ def format_results(results):
|
|
| 76 |
return formatted
|
| 77 |
|
| 78 |
def main():
|
| 79 |
-
st.title("
|
| 80 |
-
st.
|
| 81 |
-
st.markdown(":white_check_mark: **:green[Run all models at once!]**")
|
| 82 |
|
| 83 |
bmc_link = "https://www.buymeacoffee.com/nuno.tome"
|
| 84 |
image_url = "https://i.giphy.com/RETzc1mj7HpZPuNf3e.webp"
|
| 85 |
image_link_markdown = f"[]({bmc_link})"
|
| 86 |
st.markdown(image_link_markdown, unsafe_allow_html=True)
|
| 87 |
|
| 88 |
-
input_image = st.file_uploader("
|
| 89 |
|
| 90 |
if input_image is not None:
|
| 91 |
image_to_classify = Image.open(input_image)
|
| 92 |
st.image(image_to_classify, caption="Uploaded Image", use_column_width=True)
|
| 93 |
|
| 94 |
-
if st.button("
|
| 95 |
results_data = []
|
| 96 |
progress_bar = st.progress(0)
|
| 97 |
status_text = st.empty()
|
|
@@ -128,7 +149,7 @@ def main():
|
|
| 128 |
|
| 129 |
if results_data:
|
| 130 |
df = pd.DataFrame(results_data)
|
| 131 |
-
st.subheader(f"
|
| 132 |
|
| 133 |
st.markdown("""
|
| 134 |
<style>
|
|
@@ -154,7 +175,7 @@ def main():
|
|
| 154 |
|
| 155 |
csv = df.to_csv(index=False).encode('utf-8')
|
| 156 |
st.download_button(
|
| 157 |
-
"
|
| 158 |
csv,
|
| 159 |
"classification_results.csv",
|
| 160 |
"text/csv",
|
|
|
|
| 13 |
if HF_TOKEN:
|
| 14 |
login(token=HF_TOKEN)
|
| 15 |
|
| 16 |
+
TRANSLATIONS = {
|
| 17 |
+
"pt-pt": {
|
| 18 |
+
"title": "Classificação de Imagens - Compara Todos os Modelos",
|
| 19 |
+
"description": "🧪 Executa **todos os modelos** de classificação de imagens do Hugging Face numa só imagem e compara os resultados num tabela interativa.",
|
| 20 |
+
"upload": "Carregar Imagem",
|
| 21 |
+
"run_button": "Executar Todos os Modelos",
|
| 22 |
+
"results": "Resultados",
|
| 23 |
+
"download": "Descarregar CSV",
|
| 24 |
+
},
|
| 25 |
+
"en-uk": {
|
| 26 |
+
"title": "Image Classification - Compare All Models",
|
| 27 |
+
"description": "🧪 Run **all** Hugging Face image classification models on a single image and compare results in an interactive table.",
|
| 28 |
+
"upload": "Upload Image",
|
| 29 |
+
"run_button": "Run All Models",
|
| 30 |
+
"results": "Results",
|
| 31 |
+
"download": "Download CSV",
|
| 32 |
+
}
|
| 33 |
+
}
|
| 34 |
+
|
| 35 |
+
lang = st.sidebar.selectbox("Language / Idioma", ["en-uk", "pt-pt"])
|
| 36 |
+
t = TRANSLATIONS[lang]
|
| 37 |
+
|
| 38 |
MODELS = [
|
| 39 |
("google/vit-base-patch16-224", "General Image Classification"),
|
| 40 |
("microsoft/resnet-50", "General Image Classification"),
|
|
|
|
| 98 |
return formatted
|
| 99 |
|
| 100 |
def main():
|
| 101 |
+
st.title(t["title"])
|
| 102 |
+
st.markdown(t["description"])
|
|
|
|
| 103 |
|
| 104 |
bmc_link = "https://www.buymeacoffee.com/nuno.tome"
|
| 105 |
image_url = "https://i.giphy.com/RETzc1mj7HpZPuNf3e.webp"
|
| 106 |
image_link_markdown = f"[]({bmc_link})"
|
| 107 |
st.markdown(image_link_markdown, unsafe_allow_html=True)
|
| 108 |
|
| 109 |
+
input_image = st.file_uploader(t["upload"])
|
| 110 |
|
| 111 |
if input_image is not None:
|
| 112 |
image_to_classify = Image.open(input_image)
|
| 113 |
st.image(image_to_classify, caption="Uploaded Image", use_column_width=True)
|
| 114 |
|
| 115 |
+
if st.button(t["run_button"], type="primary"):
|
| 116 |
results_data = []
|
| 117 |
progress_bar = st.progress(0)
|
| 118 |
status_text = st.empty()
|
|
|
|
| 149 |
|
| 150 |
if results_data:
|
| 151 |
df = pd.DataFrame(results_data)
|
| 152 |
+
st.subheader(f"{t['results']} ({len(results_data)} models)")
|
| 153 |
|
| 154 |
st.markdown("""
|
| 155 |
<style>
|
|
|
|
| 175 |
|
| 176 |
csv = df.to_csv(index=False).encode('utf-8')
|
| 177 |
st.download_button(
|
| 178 |
+
t["download"],
|
| 179 |
csv,
|
| 180 |
"classification_results.csv",
|
| 181 |
"text/csv",
|