Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -9,23 +9,25 @@ model = tf.keras.models.load_model("is_cat.keras")
|
|
| 9 |
translations = {
|
| 10 |
"ru": {
|
| 11 |
"title": "Определитель котов 🐈 vs 🚫🐈",
|
| 12 |
-
"description": "
|
| 13 |
-
"cat_result": "
|
| 14 |
-
"
|
|
|
|
| 15 |
"examples_label": "Примеры:",
|
| 16 |
"button_text": "Определить"
|
| 17 |
},
|
| 18 |
"en": {
|
| 19 |
"title": "Cat Detector 🐈 vs 🚫🐈",
|
| 20 |
-
"description": "
|
| 21 |
-
"cat_result": "
|
| 22 |
-
"
|
|
|
|
| 23 |
"examples_label": "Examples:",
|
| 24 |
"button_text": "Detect"
|
| 25 |
}
|
| 26 |
}
|
| 27 |
|
| 28 |
-
|
| 29 |
lang_code = "ru" if lang == "Русский (ru)" else "en"
|
| 30 |
|
| 31 |
# Преобразование изображения
|
|
@@ -33,13 +35,15 @@ def predict(image, lang):
|
|
| 33 |
image = np.array(image) / 255.0
|
| 34 |
image = np.expand_dims(image, axis=0)
|
| 35 |
|
| 36 |
-
# Предсказание
|
| 37 |
pred = model.predict(image)[0][0]
|
| 38 |
-
confidence = f"{100*(1-pred if pred < 0.
|
| 39 |
|
| 40 |
-
if pred < 0.
|
| 41 |
return translations[lang_code]["cat_result"].format(confidence=confidence)
|
| 42 |
-
|
|
|
|
|
|
|
| 43 |
return translations[lang_code]["not_cat_result"].format(confidence=confidence)
|
| 44 |
|
| 45 |
with gr.Blocks() as demo:
|
|
|
|
| 9 |
translations = {
|
| 10 |
"ru": {
|
| 11 |
"title": "Определитель котов 🐈 vs 🚫🐈",
|
| 12 |
+
"description": "Модель определяет только явных котов (порог 70%)",
|
| 13 |
+
"cat_result": "Точно кот! 😻 (Уверенность: {confidence}%)",
|
| 14 |
+
"not_sure_result": "Не уверен 🤔 (Уверенность: {confidence}%)",
|
| 15 |
+
"not_cat_result": "Точно не кот! 😾 (Уверенность: {confidence}%)",
|
| 16 |
"examples_label": "Примеры:",
|
| 17 |
"button_text": "Определить"
|
| 18 |
},
|
| 19 |
"en": {
|
| 20 |
"title": "Cat Detector 🐈 vs 🚫🐈",
|
| 21 |
+
"description": "Model detects only obvious cats (70% threshold)",
|
| 22 |
+
"cat_result": "Definitely cat! 😻 (Confidence: {confidence}%)",
|
| 23 |
+
"not_sure_result": "Not sure 🤔 (Confidence: {confidence}%)",
|
| 24 |
+
"not_cat_result": "Definitely not cat! 😾 (Confidence: {confidence}%)",
|
| 25 |
"examples_label": "Examples:",
|
| 26 |
"button_text": "Detect"
|
| 27 |
}
|
| 28 |
}
|
| 29 |
|
| 30 |
+
ddef predict(image, lang):
|
| 31 |
lang_code = "ru" if lang == "Русский (ru)" else "en"
|
| 32 |
|
| 33 |
# Преобразование изображения
|
|
|
|
| 35 |
image = np.array(image) / 255.0
|
| 36 |
image = np.expand_dims(image, axis=0)
|
| 37 |
|
| 38 |
+
# Предсказание с новым порогом
|
| 39 |
pred = model.predict(image)[0][0]
|
| 40 |
+
confidence = f"{100*(1-pred if pred < 0.7 else pred):.1f}"
|
| 41 |
|
| 42 |
+
if pred < 0.3: # Точно кот (70% уверенности что это кот)
|
| 43 |
return translations[lang_code]["cat_result"].format(confidence=confidence)
|
| 44 |
+
elif pred < 0.7: # Не уверен (30-70%)
|
| 45 |
+
return translations[lang_code]["not_sure_result"].format(confidence=confidence)
|
| 46 |
+
else: # Точно не кот (>70% уверенности что не кот)
|
| 47 |
return translations[lang_code]["not_cat_result"].format(confidence=confidence)
|
| 48 |
|
| 49 |
with gr.Blocks() as demo:
|