Spaces:
Runtime error
Runtime error
| import gradio as gr | |
| import pytesseract | |
| from PIL import Image | |
| import os | |
| def extract_text(image_path): | |
| if not image_path: | |
| return "No image uploaded. Please upload an image." | |
| if not os.path.exists(image_path): | |
| return f"Error: File not found at {image_path}" | |
| try: | |
| img = Image.open(image_path) | |
| text = pytesseract.image_to_string(img) | |
| return text if text.strip() else "No text detected in the image." | |
| except Exception as e: | |
| return f"An error occurred: {str(e)}" | |
| iface = gr.Interface( | |
| fn=extract_text, | |
| inputs=gr.Image(type="filepath", label="Upload an image"), | |
| outputs=gr.Textbox(label="Extracted Text"), | |
| title="Image Text Extractor", | |
| description="Upload an image and extract text from it using OCR." | |
| ) | |
| iface.launch(server_name="0.0.0.0", server_port=7860) | |