May222 commited on
Commit
8b1afd7
1 Parent(s): f9a26b0

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +27 -34
app.py CHANGED
@@ -1,42 +1,12 @@
1
- # import gradio as gr
2
- # from transformers import pipeline
3
  from PIL import Image
4
  import pytesseract
5
  import easyocr
6
  import cv2
7
  import os
8
-
9
- # pipeline = pipeline(task="image-classification", model="julien-c/hotdog-not-hotdog")
10
-
11
- # def predict(input_img):
12
- # predictions = pipeline(input_img)
13
- # return input_img, {p["label"]: p["score"] for p in predictions}
14
-
15
- # def recognize(input_img):
16
- # text = pytesseract.image_to_string(Image.open("./data/" + filename))
17
- # return input_img, text
18
-
19
- # gradio_app = gr.Interface(
20
- # recognize,
21
- # inputs=[gr.Image(label="Upload an Image", type="pil")],
22
- # outputs=[gr.Textbox(label="Text in the Image")],
23
-
24
- # title="Extrate Text From Image",
25
- # )
26
-
27
- # if __name__ == "__main__":
28
- # gradio_app.launch(server_port=8756)
29
-
30
-
31
- import os
32
 
33
  import matplotlib.pyplot as plt
34
- import streamlit as st
35
-
36
- import cv2
37
- import tensorflow as tf
38
- from PIL import Image
39
- import pytesseract
40
 
41
  DET_ARCHS = ["pytesseract", "easyocr"]
42
 
@@ -83,7 +53,7 @@ def main():
83
  else:
84
  with st.spinner(type(doc)):
85
  if det_arch == 'pytesseract':
86
- predictor = pytesseract.image_to_string(doc)
87
  else:
88
  reader = easyocr.Reader(['en'])
89
  predictor = reader.readtext(doc, detail = 0)
@@ -97,4 +67,27 @@ def main():
97
 
98
 
99
  if __name__ == '__main__':
100
- main()
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  from PIL import Image
2
  import pytesseract
3
  import easyocr
4
  import cv2
5
  import os
6
+ from io import BytesIO
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
7
 
8
  import matplotlib.pyplot as plt
9
+ import streamlit as st
 
 
 
 
 
10
 
11
  DET_ARCHS = ["pytesseract", "easyocr"]
12
 
 
53
  else:
54
  with st.spinner(type(doc)):
55
  if det_arch == 'pytesseract':
56
+ predictor = pytesseract.image_to_string(Image.open(BytesIO(doc)))
57
  else:
58
  reader = easyocr.Reader(['en'])
59
  predictor = reader.readtext(doc, detail = 0)
 
67
 
68
 
69
  if __name__ == '__main__':
70
+ main()
71
+
72
+
73
+
74
+ # pipeline = pipeline(task="image-classification", model="julien-c/hotdog-not-hotdog")
75
+
76
+ # def predict(input_img):
77
+ # predictions = pipeline(input_img)
78
+ # return input_img, {p["label"]: p["score"] for p in predictions}
79
+
80
+ # def recognize(input_img):
81
+ # text = pytesseract.image_to_string(Image.open("./data/" + filename))
82
+ # return input_img, text
83
+
84
+ # gradio_app = gr.Interface(
85
+ # recognize,
86
+ # inputs=[gr.Image(label="Upload an Image", type="pil")],
87
+ # outputs=[gr.Textbox(label="Text in the Image")],
88
+
89
+ # title="Extrate Text From Image",
90
+ # )
91
+
92
+ # if __name__ == "__main__":
93
+ # gradio_app.launch(server_port=8756)