File size: 1,712 Bytes
ad09225
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
55
56
57
58
59
60
61
62
63
64
65

"""
Simple loading script for pixeltext-ai model
"""

from transformers import AutoModel
from PIL import Image

def load_pixeltext_model():
    """Load the pixeltext-ai model properly."""
    
    # Method 1: Direct loading (recommended)
    try:
        from modeling_pixeltext import FixedPaliGemmaOCR
        model = FixedPaliGemmaOCR()
        return model
    except Exception as e:
        print(f"Direct loading failed: {e}")
        
        # Method 2: Fallback to AutoModel
        try:
            model = AutoModel.from_pretrained(
                "BabaK07/pixeltext-ai", 
                trust_remote_code=True
            )
            return model
        except Exception as e2:
            print(f"AutoModel loading failed: {e2}")
            return None

def test_model():
    """Test the loaded model."""
    
    model = load_pixeltext_model()
    if model is None:
        print("❌ Failed to load model")
        return
    
    # Create test image
    from PIL import Image, ImageDraw, ImageFont
    
    img = Image.new('RGB', (400, 200), color='white')
    draw = ImageDraw.Draw(img)
    
    try:
        font = ImageFont.truetype("/System/Library/Fonts/Arial.ttf", 20)
    except:
        font = ImageFont.load_default()
    
    draw.text((20, 50), "Hello World!", fill='black', font=font)
    draw.text((20, 100), "This is a test for pixeltext-ai", fill='blue', font=font)
    
    # Test OCR
    result = model.generate_ocr_text(img)
    
    print("📝 OCR Results:")
    print(f"   Text: {result['text']}")
    print(f"   Confidence: {result['confidence']:.3f}")
    print(f"   Quality: {result['quality']}")
    
    return result

if __name__ == "__main__":
    test_model()