Spaces:
Sleeping
Sleeping
Upload app.py
Browse files
app.py
CHANGED
|
@@ -167,10 +167,6 @@ def stream_ocr(image):
|
|
| 167 |
return
|
| 168 |
|
| 169 |
try:
|
| 170 |
-
# Load image if it's a filepath (compatibility for type="filepath")
|
| 171 |
-
if isinstance(image, str):
|
| 172 |
-
image = Image.open(image).convert("RGB")
|
| 173 |
-
|
| 174 |
# Resize - Crucial for CPU speed
|
| 175 |
valid_image = resize_for_ocr(image, max_dim=896)
|
| 176 |
|
|
@@ -243,12 +239,11 @@ data_dir = os.path.join(base_dir, 'data')
|
|
| 243 |
if os.path.exists(data_dir):
|
| 244 |
valid_exts = {".jpg", ".jpeg", ".png", ".bmp", ".webp"}
|
| 245 |
|
| 246 |
-
#
|
| 247 |
-
# Relative paths often cause issues with component population in Spaces.
|
| 248 |
found_files = [f for f in os.listdir(data_dir) if os.path.splitext(f)[1].lower() in valid_exts]
|
| 249 |
print(f"DEBUG: Found {len(found_files)} images in {data_dir}")
|
| 250 |
|
| 251 |
-
# Use
|
| 252 |
example_images = [[os.path.join(data_dir, f)] for f in found_files]
|
| 253 |
|
| 254 |
# Limit to 5 examples to prevent UI clutter if many files exist
|
|
@@ -351,9 +346,10 @@ with gr.Blocks(title="Ultra OCR", theme=theme, css=custom_css) as demo:
|
|
| 351 |
with gr.Row(equal_height=False, variant="panel"):
|
| 352 |
with gr.Column(scale=4):
|
| 353 |
input_img = gr.Image(
|
| 354 |
-
type="
|
| 355 |
label="📄 Document Source",
|
| 356 |
height=500,
|
|
|
|
| 357 |
format="png"
|
| 358 |
)
|
| 359 |
run_btn = gr.Button("⚡ Start Transcription", variant="primary", size="lg")
|
|
@@ -390,12 +386,7 @@ with gr.Blocks(title="Ultra OCR", theme=theme, css=custom_css) as demo:
|
|
| 390 |
|
| 391 |
if __name__ == "__main__":
|
| 392 |
# Fix for spaces visual/SSR errors: Disable SSR
|
| 393 |
-
# explicitly allow the data directory and the current directory
|
| 394 |
-
allowed = [os.path.dirname(os.path.abspath(__file__))]
|
| 395 |
-
if os.path.exists(data_dir):
|
| 396 |
-
allowed.append(data_dir)
|
| 397 |
-
|
| 398 |
demo.launch(
|
| 399 |
-
allowed_paths=
|
| 400 |
ssr_mode=False
|
| 401 |
)
|
|
|
|
| 167 |
return
|
| 168 |
|
| 169 |
try:
|
|
|
|
|
|
|
|
|
|
|
|
|
| 170 |
# Resize - Crucial for CPU speed
|
| 171 |
valid_image = resize_for_ocr(image, max_dim=896)
|
| 172 |
|
|
|
|
| 239 |
if os.path.exists(data_dir):
|
| 240 |
valid_exts = {".jpg", ".jpeg", ".png", ".bmp", ".webp"}
|
| 241 |
|
| 242 |
+
# Found files list
|
|
|
|
| 243 |
found_files = [f for f in os.listdir(data_dir) if os.path.splitext(f)[1].lower() in valid_exts]
|
| 244 |
print(f"DEBUG: Found {len(found_files)} images in {data_dir}")
|
| 245 |
|
| 246 |
+
# Use ABSOLUTE paths for robustness (matches app.py logic which works)
|
| 247 |
example_images = [[os.path.join(data_dir, f)] for f in found_files]
|
| 248 |
|
| 249 |
# Limit to 5 examples to prevent UI clutter if many files exist
|
|
|
|
| 346 |
with gr.Row(equal_height=False, variant="panel"):
|
| 347 |
with gr.Column(scale=4):
|
| 348 |
input_img = gr.Image(
|
| 349 |
+
type="pil",
|
| 350 |
label="📄 Document Source",
|
| 351 |
height=500,
|
| 352 |
+
sources=['upload', 'clipboard'],
|
| 353 |
format="png"
|
| 354 |
)
|
| 355 |
run_btn = gr.Button("⚡ Start Transcription", variant="primary", size="lg")
|
|
|
|
| 386 |
|
| 387 |
if __name__ == "__main__":
|
| 388 |
# Fix for spaces visual/SSR errors: Disable SSR
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 389 |
demo.launch(
|
| 390 |
+
allowed_paths=[os.path.dirname(os.path.abspath(__file__))],
|
| 391 |
ssr_mode=False
|
| 392 |
)
|