File size: 1,647 Bytes
b5fcd8b
efc9079
0d7536c
b5fcd8b
efc9079
0d7536c
 
 
d37d4c9
0d7536c
18939e1
b5fcd8b
efc9079
b5fcd8b
18939e1
 
efc9079
 
76915f3
0d7536c
 
76915f3
0d7536c
 
d37d4c9
 
 
 
 
 
 
 
 
 
 
 
efc9079
d37d4c9
 
 
 
 
 
 
 
b5fcd8b
d37d4c9
b5fcd8b
18939e1
b5fcd8b
efc9079
0d7536c
 
18939e1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
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()