And00drew commited on
Commit
24be6f5
·
verified ·
1 Parent(s): a33cf73

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +21 -5
app.py CHANGED
@@ -4,6 +4,7 @@ from PIL import Image
4
  import gradio as gr
5
  import logging
6
  from functools import lru_cache
 
7
 
8
  # Настройка логирования
9
  logging.basicConfig(level=logging.INFO)
@@ -79,6 +80,23 @@ def classify_image(image):
79
  "available_labels": list(model.config.id2label.values())[:10] + ["..."]
80
  }
81
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
82
  # Создание интерфейса Gradio
83
  iface = gr.Interface(
84
  fn=classify_image,
@@ -86,10 +104,7 @@ iface = gr.Interface(
86
  outputs=gr.JSON(label="Classification Results"),
87
  title="🐟 Fish Species Classifier",
88
  description="Upload an image of a fish to identify its species",
89
- examples=[
90
- ["salmon.jpg"],
91
- ["trout.jpg"]
92
- ],
93
  allow_flagging="never"
94
  )
95
 
@@ -97,5 +112,6 @@ iface = gr.Interface(
97
  if __name__ == "__main__":
98
  iface.launch(
99
  server_name="0.0.0.0",
100
- server_port=7860
 
101
  )
 
4
  import gradio as gr
5
  import logging
6
  from functools import lru_cache
7
+ import os
8
 
9
  # Настройка логирования
10
  logging.basicConfig(level=logging.INFO)
 
80
  "available_labels": list(model.config.id2label.values())[:10] + ["..."]
81
  }
82
 
83
+ # Проверка существования файлов примеров
84
+ def check_example_files(example_list):
85
+ valid_examples = []
86
+ for example in example_list:
87
+ if os.path.exists(example[0]):
88
+ valid_examples.append(example)
89
+ else:
90
+ logger.warning(f"Example file not found: {example[0]}")
91
+ return valid_examples
92
+
93
+ # Примеры изображений (убедитесь, что файлы существуют)
94
+ example_files = [
95
+ ["salmon.jpg"],
96
+ ["trout.jpg"]
97
+ ]
98
+ valid_examples = check_example_files(example_files)
99
+
100
  # Создание интерфейса Gradio
101
  iface = gr.Interface(
102
  fn=classify_image,
 
104
  outputs=gr.JSON(label="Classification Results"),
105
  title="🐟 Fish Species Classifier",
106
  description="Upload an image of a fish to identify its species",
107
+ examples=valid_examples if valid_examples else None, # Используем только существующие файлы
 
 
 
108
  allow_flagging="never"
109
  )
110
 
 
112
  if __name__ == "__main__":
113
  iface.launch(
114
  server_name="0.0.0.0",
115
+ server_port=7860,
116
+ cache_examples=False # Отключаем кэширование примеров
117
  )