Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -134,6 +134,7 @@ def load_model():
|
|
| 134 |
return False
|
| 135 |
return True
|
| 136 |
|
|
|
|
| 137 |
def perform_ocr(image):
|
| 138 |
"""Main OCR function with proper error handling."""
|
| 139 |
try:
|
|
@@ -150,7 +151,17 @@ def perform_ocr(image):
|
|
| 150 |
logger.error(f"Error in perform_ocr: {e}")
|
| 151 |
return f"An error occurred: {str(e)}"
|
| 152 |
|
| 153 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 154 |
def create_interface():
|
| 155 |
"""Create the Gradio interface with proper configuration."""
|
| 156 |
|
|
@@ -236,16 +247,6 @@ def create_interface():
|
|
| 236 |
""")
|
| 237 |
|
| 238 |
# Set up processing flow
|
| 239 |
-
def process_with_status(image):
|
| 240 |
-
if image is None:
|
| 241 |
-
return "Please upload an image.", "No image provided"
|
| 242 |
-
|
| 243 |
-
try:
|
| 244 |
-
result = perform_ocr(image)
|
| 245 |
-
return result, "Processing completed successfully"
|
| 246 |
-
except Exception as e:
|
| 247 |
-
return f"Error: {str(e)}", f"Error occurred: {str(e)}"
|
| 248 |
-
|
| 249 |
submit_btn.click(
|
| 250 |
fn=process_with_status,
|
| 251 |
inputs=image_input,
|
|
@@ -273,4 +274,4 @@ if __name__ == "__main__":
|
|
| 273 |
server_port=7860,
|
| 274 |
share=False,
|
| 275 |
debug=True
|
| 276 |
-
)
|
|
|
|
| 134 |
return False
|
| 135 |
return True
|
| 136 |
|
| 137 |
+
@spaces.GPU
|
| 138 |
def perform_ocr(image):
|
| 139 |
"""Main OCR function with proper error handling."""
|
| 140 |
try:
|
|
|
|
| 151 |
logger.error(f"Error in perform_ocr: {e}")
|
| 152 |
return f"An error occurred: {str(e)}"
|
| 153 |
|
| 154 |
+
def process_with_status(image):
|
| 155 |
+
"""Process image and return result with status - moved outside to avoid pickling issues."""
|
| 156 |
+
if image is None:
|
| 157 |
+
return "Please upload an image.", "No image provided"
|
| 158 |
+
|
| 159 |
+
try:
|
| 160 |
+
result = perform_ocr(image)
|
| 161 |
+
return result, "Processing completed successfully"
|
| 162 |
+
except Exception as e:
|
| 163 |
+
return f"Error: {str(e)}", f"Error occurred: {str(e)}"
|
| 164 |
+
|
| 165 |
def create_interface():
|
| 166 |
"""Create the Gradio interface with proper configuration."""
|
| 167 |
|
|
|
|
| 247 |
""")
|
| 248 |
|
| 249 |
# Set up processing flow
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 250 |
submit_btn.click(
|
| 251 |
fn=process_with_status,
|
| 252 |
inputs=image_input,
|
|
|
|
| 274 |
server_port=7860,
|
| 275 |
share=False,
|
| 276 |
debug=True
|
| 277 |
+
)
|