BabaK07 commited on
Commit
ad09225
·
verified ·
1 Parent(s): e086da6

Fix load_model.py for proper loading

Browse files
Files changed (1) hide show
  1. load_model.py +64 -0
load_model.py ADDED
@@ -0,0 +1,64 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+
2
+ """
3
+ Simple loading script for pixeltext-ai model
4
+ """
5
+
6
+ from transformers import AutoModel
7
+ from PIL import Image
8
+
9
+ def load_pixeltext_model():
10
+ """Load the pixeltext-ai model properly."""
11
+
12
+ # Method 1: Direct loading (recommended)
13
+ try:
14
+ from modeling_pixeltext import FixedPaliGemmaOCR
15
+ model = FixedPaliGemmaOCR()
16
+ return model
17
+ except Exception as e:
18
+ print(f"Direct loading failed: {e}")
19
+
20
+ # Method 2: Fallback to AutoModel
21
+ try:
22
+ model = AutoModel.from_pretrained(
23
+ "BabaK07/pixeltext-ai",
24
+ trust_remote_code=True
25
+ )
26
+ return model
27
+ except Exception as e2:
28
+ print(f"AutoModel loading failed: {e2}")
29
+ return None
30
+
31
+ def test_model():
32
+ """Test the loaded model."""
33
+
34
+ model = load_pixeltext_model()
35
+ if model is None:
36
+ print("❌ Failed to load model")
37
+ return
38
+
39
+ # Create test image
40
+ from PIL import Image, ImageDraw, ImageFont
41
+
42
+ img = Image.new('RGB', (400, 200), color='white')
43
+ draw = ImageDraw.Draw(img)
44
+
45
+ try:
46
+ font = ImageFont.truetype("/System/Library/Fonts/Arial.ttf", 20)
47
+ except:
48
+ font = ImageFont.load_default()
49
+
50
+ draw.text((20, 50), "Hello World!", fill='black', font=font)
51
+ draw.text((20, 100), "This is a test for pixeltext-ai", fill='blue', font=font)
52
+
53
+ # Test OCR
54
+ result = model.generate_ocr_text(img)
55
+
56
+ print("📝 OCR Results:")
57
+ print(f" Text: {result['text']}")
58
+ print(f" Confidence: {result['confidence']:.3f}")
59
+ print(f" Quality: {result['quality']}")
60
+
61
+ return result
62
+
63
+ if __name__ == "__main__":
64
+ test_model()