Spaces:
Runtime error
Runtime error
Commit
·
49ae21d
1
Parent(s):
5595abb
Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Install Tesseract and the pytesseract library
|
| 2 |
+
# Import necessary libraries
|
| 3 |
+
|
| 4 |
+
from PIL import Image
|
| 5 |
+
import pytesseract
|
| 6 |
+
import gradio as gr
|
| 7 |
+
|
| 8 |
+
# Define a function to extract text from an image
|
| 9 |
+
def extract_text_from_image(image_path):
|
| 10 |
+
try:
|
| 11 |
+
# Open the image file
|
| 12 |
+
img = Image.open(image_path)
|
| 13 |
+
|
| 14 |
+
# Use Tesseract to extract text
|
| 15 |
+
text = pytesseract.image_to_string(img)
|
| 16 |
+
|
| 17 |
+
return text
|
| 18 |
+
except Exception as e:
|
| 19 |
+
return str(e)
|
| 20 |
+
|
| 21 |
+
# Define Gradio interface
|
| 22 |
+
iface = gr.Interface(
|
| 23 |
+
fn=extract_text_from_image,
|
| 24 |
+
inputs=gr.Image(type="file", label="Upload an image"),
|
| 25 |
+
outputs="text"
|
| 26 |
+
)
|
| 27 |
+
|
| 28 |
+
# Launch Gradio interface
|
| 29 |
+
iface.launch(share=True)
|