Tho Bui commited on
Commit
6bccbd3
1 Parent(s): 09f5728
Files changed (4) hide show
  1. .gitignore +24 -0
  2. README.md +4 -1
  3. app.py +58 -0
  4. requirements.txt +0 -0
.gitignore ADDED
@@ -0,0 +1,24 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Virtual environment
2
+ venv/
3
+
4
+ # Byte-compiled / optimized / DLL files
5
+ __pycache__/
6
+ *.pyc
7
+ *.pyo
8
+ *.pyd
9
+
10
+ # Compiled C extension
11
+ *.so
12
+
13
+ # Distribution / packaging
14
+ dist/
15
+ build/
16
+ *.egg-info/
17
+
18
+ # Local development
19
+ db.sqlite3
20
+
21
+ # IDE files
22
+ .vscode/
23
+ .idea/
24
+ .env
README.md CHANGED
@@ -8,5 +8,8 @@ sdk_version: 4.19.2
8
  app_file: app.py
9
  pinned: false
10
  ---
11
-
 
 
 
12
  Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
 
8
  app_file: app.py
9
  pinned: false
10
  ---
11
+ python3 -m venv venv
12
+ venv\Scripts\activate
13
+ pip freeze > requirements.txt
14
+ pip install -r requirements.txt
15
  Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
app.py ADDED
@@ -0,0 +1,58 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ from dotenv import load_dotenv, find_dotenv
3
+ import easyocr
4
+
5
+ _ = load_dotenv(find_dotenv())
6
+
7
+ out_textbox = gr.TextArea(
8
+ label="Output",
9
+ info="Data extracted",
10
+ lines=10,
11
+ value="",
12
+ interactive= True
13
+
14
+ )
15
+
16
+
17
+ def process(filepath):
18
+ reader = easyocr.Reader(['en'],gpu=True)
19
+ result = reader.readtext(filepath, batch_size=3)
20
+
21
+ latest_x = 0
22
+ latest_y = 0
23
+ content = ""
24
+ x_to_charactor = 0
25
+ for x,y,z in result:
26
+ current_x = x[0][0]
27
+ current_y = x[0][1]
28
+ if x_to_charactor == 0:
29
+ x_to_charactor = (x[1][0] - x[0][0])/(len(y))
30
+ if current_y - latest_y > 10:
31
+ content += f"""
32
+ """
33
+ num_space = int((current_x - 0)/x_to_charactor)
34
+ if num_space > 1 and latest_x != 0:
35
+ for i in range(num_space):
36
+ content += f""" """
37
+ content += f"""{y}"""
38
+ else:
39
+ num_space = int((current_x - latest_x)/x_to_charactor)
40
+ if num_space > 1 and latest_x != 0:
41
+ for i in range(num_space):
42
+ content += f""" """
43
+ content += f""" {y}"""
44
+ latest_x = x[1][0]
45
+ latest_y = current_y
46
+
47
+ yield content
48
+
49
+ with gr.Blocks() as demo:
50
+ gr.Interface(
51
+ process,
52
+ [gr.Image(type="filepath")],
53
+ [out_textbox],
54
+ flagging_options=[],
55
+ examples=[]
56
+ )
57
+
58
+ demo.launch(server_name="0.0.0.0", server_port=7860)
requirements.txt ADDED
Binary file (3.36 kB). View file