Faiza213 commited on
Commit
662e0d0
1 Parent(s): 2ce1e4f

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +23 -0
app.py ADDED
@@ -0,0 +1,23 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from transformers import MgpstrProcessor, MgpstrForSceneTextRecognition
2
+ import requests
3
+ from PIL import Image
4
+
5
+ # Load processor and model
6
+ processor = MgpstrProcessor.from_pretrained('alibaba-damo/mgp-str-base')
7
+ model = MgpstrForSceneTextRecognition.from_pretrained('alibaba-damo/mgp-str-base')
8
+
9
+ # Load image from a URL
10
+ url = "https://i.postimg.cc/ZKwLg2Gw/367-14.png"
11
+ image = Image.open(requests.get(url, stream=True).raw).convert("RGB")
12
+
13
+ # Process the image
14
+ pixel_values = processor(images=image, return_tensors="pt").pixel_values
15
+
16
+ # Perform inference
17
+ outputs = model(pixel_values)
18
+
19
+ # Decode the output
20
+ generated_text = processor.batch_decode(outputs.logits, skip_special_tokens=True)
21
+
22
+ # Print the recognized text
23
+ print("Recognized Text:", generated_text[0])