ShashwatGupta23 commited on
Commit
4dfed21
·
1 Parent(s): 75af375

Fix Gradio 4.49 pil images and HF launch (no share)

Browse files
Files changed (4) hide show
  1. README.md +1 -1
  2. app.py +8 -11
  3. requirements.txt +2 -1
  4. setup.sh +3 -1
README.md CHANGED
@@ -4,7 +4,7 @@ emoji: 🔬
4
  colorFrom: blue
5
  colorTo: green
6
  sdk: gradio
7
- sdk_version: "4.44.0"
8
  python_version: "3.10"
9
  app_file: app.py
10
  pinned: false
 
4
  colorFrom: blue
5
  colorTo: green
6
  sdk: gradio
7
+ sdk_version: "4.49.1"
8
  python_version: "3.10"
9
  app_file: app.py
10
  pinned: false
app.py CHANGED
@@ -39,7 +39,6 @@ def run_demo(defect_img, reference_img):
39
 
40
  defect_rgb, ref_rgb, enriched_rgb = enrich_pair(defect_img, reference_img)
41
 
42
- # Side-by-side comparison for the demo panel
43
  h = max(defect_rgb.shape[0], ref_rgb.shape[0], enriched_rgb.shape[0])
44
 
45
  def _pad(im: np.ndarray) -> np.ndarray:
@@ -49,7 +48,7 @@ def run_demo(defect_img, reference_img):
49
  return np.pad(im, ((0, pad), (0, 0), (0, 0)), mode="constant", constant_values=114)
50
 
51
  row = np.concatenate([_pad(defect_rgb), _pad(ref_rgb), _pad(enriched_rgb)], axis=1)
52
- return enriched_rgb, row
53
 
54
 
55
  def _preload_model():
@@ -67,17 +66,13 @@ if __name__ == "__main__":
67
  gr.Markdown(DESCRIPTION)
68
 
69
  with gr.Row():
70
- defect_in = gr.Image(label="Defect image (input)", type="numpy", image_mode="RGB")
71
- ref_in = gr.Image(label="Golden reference", type="numpy", image_mode="RGB")
72
 
73
  run_btn = gr.Button("Generate enriched image", variant="primary")
74
  with gr.Row():
75
- enriched_out = gr.Image(label="Enriched output", type="numpy", image_mode="RGB")
76
- compare_out = gr.Image(
77
- label="Defect | Reference | Enriched",
78
- type="numpy",
79
- image_mode="RGB",
80
- )
81
 
82
  run_btn.click(fn=run_demo, inputs=[defect_in, ref_in], outputs=[enriched_out, compare_out])
83
 
@@ -85,8 +80,10 @@ if __name__ == "__main__":
85
  if ex:
86
  gr.Examples(examples=ex, inputs=[defect_in, ref_in], label="Example pairs")
87
 
 
88
  demo.launch(
89
  server_name="0.0.0.0",
90
  server_port=int(os.environ.get("PORT", "7860")),
91
- share=os.environ.get("GRADIO_SHARE", "").lower() in {"1", "true", "yes"},
 
92
  )
 
39
 
40
  defect_rgb, ref_rgb, enriched_rgb = enrich_pair(defect_img, reference_img)
41
 
 
42
  h = max(defect_rgb.shape[0], ref_rgb.shape[0], enriched_rgb.shape[0])
43
 
44
  def _pad(im: np.ndarray) -> np.ndarray:
 
48
  return np.pad(im, ((0, pad), (0, 0), (0, 0)), mode="constant", constant_values=114)
49
 
50
  row = np.concatenate([_pad(defect_rgb), _pad(ref_rgb), _pad(enriched_rgb)], axis=1)
51
+ return Image.fromarray(enriched_rgb), Image.fromarray(row)
52
 
53
 
54
  def _preload_model():
 
66
  gr.Markdown(DESCRIPTION)
67
 
68
  with gr.Row():
69
+ defect_in = gr.Image(label="Defect image (input)", type="pil", image_mode="RGB")
70
+ ref_in = gr.Image(label="Golden reference", type="pil", image_mode="RGB")
71
 
72
  run_btn = gr.Button("Generate enriched image", variant="primary")
73
  with gr.Row():
74
+ enriched_out = gr.Image(label="Enriched output", type="pil", image_mode="RGB")
75
+ compare_out = gr.Image(label="Defect | Reference | Enriched", type="pil", image_mode="RGB")
 
 
 
 
76
 
77
  run_btn.click(fn=run_demo, inputs=[defect_in, ref_in], outputs=[enriched_out, compare_out])
78
 
 
80
  if ex:
81
  gr.Examples(examples=ex, inputs=[defect_in, ref_in], label="Example pairs")
82
 
83
+ # HF Spaces: bind 0.0.0.0, never use share=True
84
  demo.launch(
85
  server_name="0.0.0.0",
86
  server_port=int(os.environ.get("PORT", "7860")),
87
+ share=False,
88
+ show_error=True,
89
  )
requirements.txt CHANGED
@@ -1,4 +1,5 @@
1
- gradio>=4.44.0
 
2
  # Python 3.13+ removed stdlib audioop; pydub (gradio dep) needs this backport
3
  audioop-lts>=0.2.1; python_version >= "3.13"
4
  torch>=2.0.0
 
1
+ gradio>=4.49.1,<5.0.0
2
+ gradio-client>=1.3.0,<1.6.0
3
  # Python 3.13+ removed stdlib audioop; pydub (gradio dep) needs this backport
4
  audioop-lts>=0.2.1; python_version >= "3.13"
5
  torch>=2.0.0
setup.sh CHANGED
@@ -2,8 +2,10 @@
2
  # Hugging Face Spaces: install vendored custom Ultralytics before app starts.
3
  set -euo pipefail
4
  cd "$(dirname "$0")"
5
- # HF base image may install huggingface_hub 1.x; Gradio 4.44 needs <1.0 (HfFolder)
6
  pip install -q "huggingface_hub>=0.23.0,<1.0"
 
 
7
 
8
  if [[ -d vendor ]]; then
9
  pip install -q -e ./vendor
 
2
  # Hugging Face Spaces: install vendored custom Ultralytics before app starts.
3
  set -euo pipefail
4
  cd "$(dirname "$0")"
5
+ # HF base image may install huggingface_hub 1.x; Gradio 4.x needs <1.0 (HfFolder)
6
  pip install -q "huggingface_hub>=0.23.0,<1.0"
7
+ export YOLO_CONFIG_DIR="${YOLO_CONFIG_DIR:-/tmp/Ultralytics}"
8
+ mkdir -p "${YOLO_CONFIG_DIR}"
9
 
10
  if [[ -d vendor ]]; then
11
  pip install -q -e ./vendor