Spaces:
Sleeping
Sleeping
Commit ·
e5f795e
1
Parent(s): 0758f02
fix
Browse files
app.py
CHANGED
|
@@ -15,7 +15,7 @@ model.eval()
|
|
| 15 |
# Function to process PDF and extract structured information
|
| 16 |
def extract_license_info(pdf_file):
|
| 17 |
if pdf_file is None:
|
| 18 |
-
return "Please upload a PDF file.", None,
|
| 19 |
|
| 20 |
try:
|
| 21 |
# Convert PDF to image
|
|
@@ -35,11 +35,24 @@ def extract_license_info(pdf_file):
|
|
| 35 |
outputs = model.generate(**inputs)
|
| 36 |
extracted_text = processor.batch_decode(outputs, skip_special_tokens=True)[0]
|
| 37 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 38 |
# Return results
|
| 39 |
-
return extracted_text, img,
|
| 40 |
|
| 41 |
except Exception as e:
|
| 42 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 43 |
|
| 44 |
# Gradio interface
|
| 45 |
with gr.Blocks(title="Driver's License Info Extractor") as demo:
|
|
|
|
| 15 |
# Function to process PDF and extract structured information
|
| 16 |
def extract_license_info(pdf_file):
|
| 17 |
if pdf_file is None:
|
| 18 |
+
return "Please upload a PDF file.", None, "**Status:** Waiting for PDF upload..."
|
| 19 |
|
| 20 |
try:
|
| 21 |
# Convert PDF to image
|
|
|
|
| 35 |
outputs = model.generate(**inputs)
|
| 36 |
extracted_text = processor.batch_decode(outputs, skip_special_tokens=True)[0]
|
| 37 |
|
| 38 |
+
# Create status message
|
| 39 |
+
status = f"""
|
| 40 |
+
✅ **Processing Complete!**
|
| 41 |
+
- Image size: {img.width} x {img.height} pixels
|
| 42 |
+
- Device: {device.upper()}
|
| 43 |
+
- Text extracted: {len(extracted_text)} characters
|
| 44 |
+
"""
|
| 45 |
+
|
| 46 |
# Return results
|
| 47 |
+
return extracted_text, img, status
|
| 48 |
|
| 49 |
except Exception as e:
|
| 50 |
+
error_status = f"""
|
| 51 |
+
❌ **Error Processing PDF**
|
| 52 |
+
- Error: {str(e)}
|
| 53 |
+
- Please try with a different PDF file
|
| 54 |
+
"""
|
| 55 |
+
return f"Error processing PDF: {str(e)}", None, error_status
|
| 56 |
|
| 57 |
# Gradio interface
|
| 58 |
with gr.Blocks(title="Driver's License Info Extractor") as demo:
|