AnatarG commited on
Commit
5847d9b
·
verified ·
1 Parent(s): 5d5f494

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +15 -11
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": "Кот! 😻 (Уверенность: {confidence}%)",
14
- "not_cat_result": "Не кот! 😾 (Уверенность: {confidence}%)",
 
15
  "examples_label": "Примеры:",
16
  "button_text": "Определить"
17
  },
18
  "en": {
19
  "title": "Cat Detector 🐈 vs 🚫🐈",
20
- "description": "Upload a photo to check if it's a cat!",
21
- "cat_result": "Cat! 😻 (Confidence: {confidence}%)",
22
- "not_cat_result": "Not a cat! 😾 (Confidence: {confidence}%)",
 
23
  "examples_label": "Examples:",
24
  "button_text": "Detect"
25
  }
26
  }
27
 
28
- def predict(image, lang):
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.5 else pred):.1f}"
39
 
40
- if pred < 0.5:
41
  return translations[lang_code]["cat_result"].format(confidence=confidence)
42
- else:
 
 
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: