Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -13,19 +13,22 @@ model = AutoModel.from_pretrained('ucaslcl/GOT-OCR2_0', trust_remote_code=True,
|
|
13 |
model = model.eval().to(device)
|
14 |
|
15 |
def extract_text(image):
|
16 |
-
|
|
|
|
|
17 |
image_path = 'temp_image.png'
|
18 |
image.save(image_path)
|
19 |
-
|
20 |
try:
|
21 |
res = model.chat(tokenizer, image_path, ocr_type='ocr')
|
22 |
-
return res, res
|
23 |
except Exception as e:
|
24 |
return f"Error: {str(e)}", ""
|
25 |
finally:
|
26 |
if os.path.exists(image_path):
|
27 |
os.remove(image_path)
|
28 |
|
|
|
29 |
def keyword_search(extracted_text, keyword):
|
30 |
if not extracted_text:
|
31 |
return "No text extracted yet."
|
|
|
13 |
model = model.eval().to(device)
|
14 |
|
15 |
def extract_text(image):
|
16 |
+
if image is None:
|
17 |
+
return "No image uploaded", ""
|
18 |
+
|
19 |
image_path = 'temp_image.png'
|
20 |
image.save(image_path)
|
21 |
+
|
22 |
try:
|
23 |
res = model.chat(tokenizer, image_path, ocr_type='ocr')
|
24 |
+
return res, res
|
25 |
except Exception as e:
|
26 |
return f"Error: {str(e)}", ""
|
27 |
finally:
|
28 |
if os.path.exists(image_path):
|
29 |
os.remove(image_path)
|
30 |
|
31 |
+
|
32 |
def keyword_search(extracted_text, keyword):
|
33 |
if not extracted_text:
|
34 |
return "No text extracted yet."
|