Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -13,7 +13,8 @@ translations = {
|
|
| 13 |
"cat_result": "Кот! 😻 (Уверенность: {confidence}%)",
|
| 14 |
"not_cat_result": "Не кот! 😾 (Уверенность: {confidence}%)",
|
| 15 |
"button_text": "Определить",
|
| 16 |
-
"switch_lang": "EN 🇺🇸"
|
|
|
|
| 17 |
},
|
| 18 |
"en": {
|
| 19 |
"title": "Cat Detector 🐈",
|
|
@@ -21,7 +22,8 @@ translations = {
|
|
| 21 |
"cat_result": "Cat! 😻 (Confidence: {confidence}%)",
|
| 22 |
"not_cat_result": "Not a cat! 😾 (Confidence: {confidence}%)",
|
| 23 |
"button_text": "Detect",
|
| 24 |
-
"switch_lang": "RU 🇷🇺"
|
|
|
|
| 25 |
}
|
| 26 |
}
|
| 27 |
|
|
@@ -49,12 +51,21 @@ def switch_language():
|
|
| 49 |
current_lang = "en" if current_lang == "ru" else "ru"
|
| 50 |
return translations[current_lang]["switch_lang"]
|
| 51 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 52 |
# Создаем интерфейс
|
| 53 |
with gr.Blocks() as demo:
|
| 54 |
# Кнопка переключения языка в правом верхнем углу
|
| 55 |
with gr.Row():
|
| 56 |
gr.Markdown("") # Пустой элемент для выравнивания
|
| 57 |
-
lang_btn = gr.Button(translations[
|
| 58 |
|
| 59 |
# Основной интерфейс
|
| 60 |
title = gr.Markdown(f"## {translations[current_lang]['title']}")
|
|
@@ -68,34 +79,20 @@ with gr.Blocks() as demo:
|
|
| 68 |
btn.click(fn=predict, inputs=image_input, outputs=output)
|
| 69 |
|
| 70 |
# Примеры изображений
|
|
|
|
| 71 |
gr.Examples(
|
| 72 |
examples=["cat.jpg", "not_cat.jpg"],
|
| 73 |
inputs=image_input,
|
| 74 |
-
label=
|
| 75 |
)
|
| 76 |
|
| 77 |
# Обработка переключения языка
|
| 78 |
-
def update_interface():
|
| 79 |
-
return {
|
| 80 |
-
title: f"## {translations[current_lang]['title']}",
|
| 81 |
-
description: translations[current_lang]["description"],
|
| 82 |
-
btn: translations[current_lang]["button_text"],
|
| 83 |
-
lang_btn: translations[current_lang]["switch_lang"]
|
| 84 |
-
}
|
| 85 |
-
|
| 86 |
lang_btn.click(
|
| 87 |
fn=switch_language,
|
| 88 |
-
outputs=lang_btn
|
| 89 |
-
_js="""
|
| 90 |
-
function() {
|
| 91 |
-
// Принудительное обновление интерфейса
|
| 92 |
-
setTimeout(() => window.dispatchEvent(new Event('resize')), 100);
|
| 93 |
-
return arguments[0];
|
| 94 |
-
}
|
| 95 |
-
"""
|
| 96 |
).then(
|
| 97 |
fn=update_interface,
|
| 98 |
-
outputs=[title, description, btn, lang_btn]
|
| 99 |
)
|
| 100 |
|
| 101 |
demo.launch()
|
|
|
|
| 13 |
"cat_result": "Кот! 😻 (Уверенность: {confidence}%)",
|
| 14 |
"not_cat_result": "Не кот! 😾 (Уверенность: {confidence}%)",
|
| 15 |
"button_text": "Определить",
|
| 16 |
+
"switch_lang": "EN 🇺🇸",
|
| 17 |
+
"examples_label": "Примеры:"
|
| 18 |
},
|
| 19 |
"en": {
|
| 20 |
"title": "Cat Detector 🐈",
|
|
|
|
| 22 |
"cat_result": "Cat! 😻 (Confidence: {confidence}%)",
|
| 23 |
"not_cat_result": "Not a cat! 😾 (Confidence: {confidence}%)",
|
| 24 |
"button_text": "Detect",
|
| 25 |
+
"switch_lang": "RU 🇷🇺",
|
| 26 |
+
"examples_label": "Examples:"
|
| 27 |
}
|
| 28 |
}
|
| 29 |
|
|
|
|
| 51 |
current_lang = "en" if current_lang == "ru" else "ru"
|
| 52 |
return translations[current_lang]["switch_lang"]
|
| 53 |
|
| 54 |
+
def update_interface():
|
| 55 |
+
return {
|
| 56 |
+
title: f"## {translations[current_lang]['title']}",
|
| 57 |
+
description: translations[current_lang]["description"],
|
| 58 |
+
btn: translations[current_lang]["button_text"],
|
| 59 |
+
lang_btn: translations[current_lang]["switch_lang"],
|
| 60 |
+
examples_label: translations[current_lang]["examples_label"]
|
| 61 |
+
}
|
| 62 |
+
|
| 63 |
# Создаем интерфейс
|
| 64 |
with gr.Blocks() as demo:
|
| 65 |
# Кнопка переключения языка в правом верхнем углу
|
| 66 |
with gr.Row():
|
| 67 |
gr.Markdown("") # Пустой элемент для выравнивания
|
| 68 |
+
lang_btn = gr.Button(translations[current_lang]["switch_lang"], size="sm")
|
| 69 |
|
| 70 |
# Основной интерфейс
|
| 71 |
title = gr.Markdown(f"## {translations[current_lang]['title']}")
|
|
|
|
| 79 |
btn.click(fn=predict, inputs=image_input, outputs=output)
|
| 80 |
|
| 81 |
# Примеры изображений
|
| 82 |
+
examples_label = gr.Label(translations[current_lang]["examples_label"])
|
| 83 |
gr.Examples(
|
| 84 |
examples=["cat.jpg", "not_cat.jpg"],
|
| 85 |
inputs=image_input,
|
| 86 |
+
label=examples_label
|
| 87 |
)
|
| 88 |
|
| 89 |
# Обработка переключения языка
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 90 |
lang_btn.click(
|
| 91 |
fn=switch_language,
|
| 92 |
+
outputs=lang_btn
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 93 |
).then(
|
| 94 |
fn=update_interface,
|
| 95 |
+
outputs=[title, description, btn, lang_btn, examples_label]
|
| 96 |
)
|
| 97 |
|
| 98 |
demo.launch()
|