Update app.py
Browse files
app.py
CHANGED
@@ -1,7 +1,7 @@
|
|
1 |
import gradio as gr
|
2 |
from transformers import AutoModel, AutoTokenizer
|
3 |
from PIL import Image
|
4 |
-
import
|
5 |
|
6 |
# Load the tokenizer and model
|
7 |
tokenizer = AutoTokenizer.from_pretrained('ucaslcl/GOT-OCR2_0', trust_remote_code=True)
|
@@ -15,11 +15,12 @@ def perform_ocr(image):
|
|
15 |
if image.mode != "RGB":
|
16 |
image = image.convert("RGB")
|
17 |
|
18 |
-
#
|
19 |
-
|
|
|
20 |
|
21 |
-
|
22 |
-
|
23 |
|
24 |
return res
|
25 |
except Exception as e:
|
|
|
1 |
import gradio as gr
|
2 |
from transformers import AutoModel, AutoTokenizer
|
3 |
from PIL import Image
|
4 |
+
import tempfile
|
5 |
|
6 |
# Load the tokenizer and model
|
7 |
tokenizer = AutoTokenizer.from_pretrained('ucaslcl/GOT-OCR2_0', trust_remote_code=True)
|
|
|
15 |
if image.mode != "RGB":
|
16 |
image = image.convert("RGB")
|
17 |
|
18 |
+
# Save the image to a temporary file
|
19 |
+
with tempfile.NamedTemporaryFile(suffix=".jpg", delete=False) as temp_file:
|
20 |
+
image.save(temp_file.name)
|
21 |
|
22 |
+
# Perform OCR using the model
|
23 |
+
res = model.chat(tokenizer, temp_file.name, ocr_type='ocr') # Pass the file path
|
24 |
|
25 |
return res
|
26 |
except Exception as e:
|