Hayk Arutyunyan commited on
Commit
38e057b
·
1 Parent(s): 3c6b13b

Fix filename handling in HF demo; switch input to gr.File; ensure correct file reading and export to Excel

Browse files
Files changed (2) hide show
  1. app.py +12 -3
  2. src/ocr_utils_demo.py +1 -1
app.py CHANGED
@@ -25,12 +25,21 @@ def draw_boxes(img_rgb, sensors):
25
  # ================================
26
  # Основная функция демо
27
  # ================================
28
- def hf_process(img):
29
 
30
  cfg = load_config("configs/config.yaml")
31
 
32
  # Имя файла (если доступно)
33
- filename = getattr(img, "name", "uploaded_image.png")
 
 
 
 
 
 
 
 
 
34
 
35
  # Запуск пайплайна
36
  title, sensors = process_single_image(img, color_ranges=cfg["colors"])
@@ -70,7 +79,7 @@ def hf_process(img):
70
  # ================================
71
  demo = gr.Interface(
72
  fn=hf_process,
73
- inputs=gr.Image(type="numpy", label="Upload image"),
74
  outputs=[
75
  gr.Image(label="Detected sensors"),
76
  gr.Textbox(label="Title"),
 
25
  # ================================
26
  # Основная функция демо
27
  # ================================
28
+ def hf_process(file):
29
 
30
  cfg = load_config("configs/config.yaml")
31
 
32
  # Имя файла (если доступно)
33
+ if hasattr(file, "name"):
34
+ file_path = file.name
35
+ else:
36
+ file_path = file # Если пришла строка
37
+
38
+ filename = Path(file_path).name
39
+
40
+ img = cv2.imread(file_path)
41
+ if img is None:
42
+ raise ValueError("Не удалось прочитать изображение")
43
 
44
  # Запуск пайплайна
45
  title, sensors = process_single_image(img, color_ranges=cfg["colors"])
 
79
  # ================================
80
  demo = gr.Interface(
81
  fn=hf_process,
82
+ inputs=gr.File(label="Upload image"),
83
  outputs=[
84
  gr.Image(label="Detected sensors"),
85
  gr.Textbox(label="Title"),
src/ocr_utils_demo.py CHANGED
@@ -85,7 +85,7 @@ def ocr_sensors(rois: list[np.ndarray]):
85
 
86
  results.append({
87
  "text": text if text else "?",
88
- "score": float(score) if score else 0.0
89
  })
90
 
91
  return results
 
85
 
86
  results.append({
87
  "text": text if text else "?",
88
+ "score": round(float(score), 2) if score else 0.0
89
  })
90
 
91
  return results