Spaces:
Runtime error
Runtime error
Commit
·
e5901da
1
Parent(s):
46275d8
Update app.py
Browse files
app.py
CHANGED
@@ -1,29 +1,22 @@
|
|
1 |
-
#
|
2 |
-
|
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 |
-
|
29 |
-
iface.launch(
|
|
|
1 |
+
# app.py
|
2 |
+
import gradio as gr
|
|
|
3 |
from PIL import Image
|
4 |
import pytesseract
|
|
|
5 |
|
|
|
6 |
def extract_text_from_image(image_path):
|
7 |
try:
|
|
|
8 |
img = Image.open(image_path)
|
|
|
|
|
9 |
text = pytesseract.image_to_string(img)
|
|
|
10 |
return text
|
11 |
except Exception as e:
|
12 |
return str(e)
|
13 |
|
|
|
14 |
iface = gr.Interface(
|
15 |
fn=extract_text_from_image,
|
16 |
inputs=gr.Image(type="file", label="Upload an image"),
|
17 |
+
outputs="text",
|
18 |
+
live=True,
|
19 |
)
|
20 |
|
21 |
+
if __name__ == "__main__":
|
22 |
+
iface.launch()
|