Oliverdsfdsf commited on
Commit
a6a15f8
·
verified ·
1 Parent(s): 4869c56

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +11 -5
app.py CHANGED
@@ -2,6 +2,7 @@ import gradio as gr
2
  from ultralytics import YOLO
3
  import numpy as np
4
  from PIL import Image
 
5
 
6
  # 1. Load your trained YOLO26n-seg model
7
  # The system looks for 'comic-panels-and-text-detect.pt' in the same directory
@@ -19,18 +20,23 @@ def predict_comic(input_image):
19
  if input_image is None:
20
  return None, "Please upload an image first."
21
 
22
- # Convert PIL Image to numpy array for YOLO processing
23
- img_array = np.array(input_image)
 
 
24
 
25
- # Execute segmentation pipeline using optimized configurations
26
- # imgsz=1280 ensures small manga text and detailed panels aren't missed
27
  results = model.predict(
28
- source=img_array,
29
  conf=0.25,
30
  iou=0.70,
31
  imgsz=1280
32
  )
33
 
 
 
 
 
34
  # Extract prediction elements from the primary image result
35
  res = results[0]
36
 
 
2
  from ultralytics import YOLO
3
  import numpy as np
4
  from PIL import Image
5
+ import os
6
 
7
  # 1. Load your trained YOLO26n-seg model
8
  # The system looks for 'comic-panels-and-text-detect.pt' in the same directory
 
20
  if input_image is None:
21
  return None, "Please upload an image first."
22
 
23
+ # 💡 CRITICAL FIX: Save to lossless raw PNG temp file.
24
+ # This prevents Gradio from altering pixel arrays and enforces native Ultralytics decoding.
25
+ tmp_path = "tmp_input_raw.png"
26
+ input_image.save(tmp_path, format="PNG", quality=100)
27
 
28
+ # Execute segmentation pipeline mirroring your exact local CLI parameters
 
29
  results = model.predict(
30
+ source=tmp_path,
31
  conf=0.25,
32
  iou=0.70,
33
  imgsz=1280
34
  )
35
 
36
+ # Safe cleanup of the temporary file
37
+ if os.path.exists(tmp_path):
38
+ os.remove(tmp_path)
39
+
40
  # Extract prediction elements from the primary image result
41
  res = results[0]
42