Spaces:
Paused
Paused
| import gradio as gr | |
| from paddleocr import PaddleOCRVL | |
| import time | |
| print("Loading PaddleOCR-VL...") | |
| pipeline = PaddleOCRVL( | |
| use_doc_orientation_classify=False, | |
| use_doc_unwarping=False, | |
| use_layout_detection=False, | |
| ) | |
| print("Model loaded!") | |
| def predict(image): | |
| if image is None: | |
| return "Загрузите изображение" | |
| temp_path = "/tmp/input.png" | |
| image.save(temp_path) | |
| print(f"[{time.strftime('%H:%M:%S')}] Processing...") | |
| t0 = time.time() | |
| output = pipeline.predict(temp_path, vl_rec_task="ocr") | |
| # Отладка - смотрим что вернулось | |
| for i, res in enumerate(output): | |
| print(f"\n=== Result {i} ===") | |
| print(f"Type: {type(res)}") | |
| print(f"Dir: {[x for x in dir(res) if not x.startswith('_')]}") | |
| if hasattr(res, '__dict__'): | |
| print(f"Dict: {res.__dict__.keys()}") | |
| print(f"Str: {str(res)[:500]}") | |
| print(f"\n[{time.strftime('%H:%M:%S')}] Done in {time.time()-t0:.1f}s") | |
| # Пробуем разные варианты | |
| for res in output: | |
| # Вариант 1 | |
| if hasattr(res, 'rec_text'): | |
| return res.rec_text | |
| # Вариант 2 | |
| if hasattr(res, 'vl_recognition_res'): | |
| return str(res.vl_recognition_res) | |
| # Вариант 3 - просто строка | |
| return str(res) | |
| return "Нет результата" | |
| gr.Interface( | |
| fn=predict, | |
| inputs=gr.Image(type="pil", label="Изображение"), | |
| outputs=gr.Textbox(label="Результат", lines=20), | |
| title="PaddleOCR-VL (OCR)", | |
| ).launch() |