Upload 3 files
Browse files- app.py +26 -0
- image4.jpg +0 -0
- img_to_txt.py +16 -0
app.py
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
from PIL import Image
|
| 3 |
+
import pytesseract
|
| 4 |
+
|
| 5 |
+
|
| 6 |
+
def recognize_text(image):
|
| 7 |
+
img = Image.fromarray(image.astype('uint8'), 'RGB')
|
| 8 |
+
text = pytesseract.image_to_string(img)
|
| 9 |
+
return text
|
| 10 |
+
|
| 11 |
+
|
| 12 |
+
input_image = gr.inputs.Image()
|
| 13 |
+
output_text = gr.outputs.Textbox()
|
| 14 |
+
|
| 15 |
+
interface = gr.Interface(
|
| 16 |
+
fn=recognize_text,
|
| 17 |
+
inputs=input_image,
|
| 18 |
+
outputs=output_text,
|
| 19 |
+
title='Image Text Recognition',
|
| 20 |
+
description='Upload an image to recognize text from it.',
|
| 21 |
+
examples=[['image/image4.jpg']],
|
| 22 |
+
allow_flagging=False
|
| 23 |
+
)
|
| 24 |
+
|
| 25 |
+
if __name__ == '__main__':
|
| 26 |
+
interface.launch(share=True)
|
image4.jpg
ADDED
|
img_to_txt.py
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
from PIL import Image
|
| 3 |
+
import pytesseract
|
| 4 |
+
|
| 5 |
+
|
| 6 |
+
image_path = input("Enter path to image file: ")
|
| 7 |
+
|
| 8 |
+
|
| 9 |
+
img = Image.open(image_path)
|
| 10 |
+
|
| 11 |
+
|
| 12 |
+
text = pytesseract.image_to_string(img)
|
| 13 |
+
|
| 14 |
+
|
| 15 |
+
print(text)
|
| 16 |
+
#interface = gr.Interface(fn=predict, inputs=input_field, outputs=output_field)
|