chenchangliu commited on
Commit
2ac1183
·
verified ·
1 Parent(s): 3d4d238

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +7 -38
app.py CHANGED
@@ -1,7 +1,4 @@
1
  import json
2
- import warnings
3
- import sys
4
-
5
  import torch
6
  import torch.nn as nn
7
  from torchvision import transforms
@@ -10,33 +7,6 @@ from PIL import Image
10
  import gradio as gr
11
 
12
 
13
- # ---- Silence noisy but harmless warnings in some environments ----
14
- warnings.filterwarnings(
15
- "ignore",
16
- category=FutureWarning,
17
- module=r"spaces\._vendor\.codefind\..*",
18
- )
19
-
20
- # Silence "Exception ignored in: BaseEventLoop.__del__ ... Invalid file descriptor: -1"
21
- # This is an unraisable exception printed during interpreter shutdown in some stacks.
22
- def _silence_asyncio_shutdown_unraisable(unraisable):
23
- try:
24
- msg = str(unraisable.exc_value)
25
- obj_name = type(unraisable.object).__name__ if unraisable.object is not None else ""
26
- if (
27
- unraisable.exc_type is ValueError
28
- and msg.startswith("Invalid file descriptor")
29
- and "EventLoop" in obj_name
30
- ):
31
- return
32
- except Exception:
33
- pass
34
- sys.__unraisablehook__(unraisable)
35
-
36
- sys.unraisablehook = _silence_asyncio_shutdown_unraisable
37
- # ---------------------------------------------------------------
38
-
39
-
40
  # ---------- CONFIG ----------
41
  CKPT_PATH = "best_effnet_twohead.pt"
42
  LABELS_PATH = "labels.json"
@@ -116,7 +86,6 @@ def predict(image: Image.Image):
116
 
117
  EXAMPLE_TEXT = """
118
  **Taxa (12):** Cacoxnus indagator, Chelostoma florisomne, Coeliopencyrtus, Eumenidae, Heriades, Hylaeus, Megachile, Osmia bicornis, Osmia cornuta, Passaloecus, Psenulus, Trypoxylon
119
-
120
  **States (4):** DauLv, DeadLv, Lv, OldFood
121
  """
122
 
@@ -130,7 +99,7 @@ STATUS_TABLE = [
130
 
131
  theme = gr.themes.Soft()
132
 
133
- with gr.Blocks(title="LTN EfficientNet Two-Head Classifier") as demo:
134
  gr.Markdown(
135
  "# EfficientNet Two-Head Layer Trap Nest (LTN) Classifier\n"
136
  "Upload a brood-cell image crop to predict **taxon** and **developmental state**.\n"
@@ -151,7 +120,7 @@ with gr.Blocks(title="LTN EfficientNet Two-Head Classifier") as demo:
151
  interactive=False,
152
  wrap=True,
153
  row_count=(len(STATUS_TABLE), "fixed"),
154
- column_count=(2, "fixed"),
155
  )
156
 
157
  with gr.Column(scale=1):
@@ -167,10 +136,10 @@ with gr.Blocks(title="LTN EfficientNet Two-Head Classifier") as demo:
167
  inputs=img,
168
  )
169
 
170
- #gr.Markdown(
171
- #"<small>Note: The status legend is a human-readable mapping. "
172
- #"Your model output labels come from `labels.json`.</small>"
173
- #)
174
 
175
  if __name__ == "__main__":
176
- demo.launch(theme=theme, ssr_mode=False, allowed_paths=["."])
 
1
  import json
 
 
 
2
  import torch
3
  import torch.nn as nn
4
  from torchvision import transforms
 
7
  import gradio as gr
8
 
9
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
10
  # ---------- CONFIG ----------
11
  CKPT_PATH = "best_effnet_twohead.pt"
12
  LABELS_PATH = "labels.json"
 
86
 
87
  EXAMPLE_TEXT = """
88
  **Taxa (12):** Cacoxnus indagator, Chelostoma florisomne, Coeliopencyrtus, Eumenidae, Heriades, Hylaeus, Megachile, Osmia bicornis, Osmia cornuta, Passaloecus, Psenulus, Trypoxylon
 
89
  **States (4):** DauLv, DeadLv, Lv, OldFood
90
  """
91
 
 
99
 
100
  theme = gr.themes.Soft()
101
 
102
+ with gr.Blocks(theme=theme, title="LTN EfficientNet Two-Head Classifier") as demo:
103
  gr.Markdown(
104
  "# EfficientNet Two-Head Layer Trap Nest (LTN) Classifier\n"
105
  "Upload a brood-cell image crop to predict **taxon** and **developmental state**.\n"
 
120
  interactive=False,
121
  wrap=True,
122
  row_count=(len(STATUS_TABLE), "fixed"),
123
+ col_count=(2, "fixed"),
124
  )
125
 
126
  with gr.Column(scale=1):
 
136
  inputs=img,
137
  )
138
 
139
+ gr.Markdown(
140
+ "<small>Note: The status legend is a human-readable mapping. "
141
+ "Your model output labels come from `labels.json`.</small>"
142
+ )
143
 
144
  if __name__ == "__main__":
145
+ demo.launch()