typesdigital commited on
Commit
e5901da
·
1 Parent(s): 46275d8

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +6 -13
app.py CHANGED
@@ -1,29 +1,22 @@
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)
 
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()