Turing311 commited on
Commit
3681b7b
·
1 Parent(s): eeeb45a
Files changed (7) hide show
  1. app.py +25 -6
  2. demo.py +8 -3
  3. examples/11.jpg +0 -0
  4. examples/12.jpg +0 -0
  5. examples/21.jpg +0 -0
  6. examples/22.jpg +0 -0
  7. examples/3.jpg +0 -0
app.py CHANGED
@@ -52,8 +52,12 @@ def ocr_idcard():
52
 
53
 
54
  ocrResult = TTVOcrProcess(file_path1.encode('utf-8'), file_path2.encode('utf-8'))
55
- ocrResDict = json.loads(ocrResult)
56
  status = "ok"
 
 
 
 
 
57
 
58
  if_check = ttv_if_checker(file_path1.encode('utf-8'))
59
  response = jsonify({"status": status, "data": ocrResDict, "authenticity": if_check})
@@ -79,8 +83,12 @@ def ocr_idcard_base64():
79
  file_path = os.path.abspath(save_path)
80
 
81
  ocrResult = TTVOcrProcess(file_path.encode('utf-8'))
82
- ocrResDict = json.loads(ocrResult)
83
  status = "ok"
 
 
 
 
 
84
 
85
  if_check = ttv_if_checker(file_path.encode('utf-8'))
86
  response = jsonify({"status": status, "data": ocrResDict, "authenticity": if_check})
@@ -105,8 +113,12 @@ def ocr_credit():
105
  file_path = os.path.abspath(save_path)
106
 
107
  ocrResult = TTVOcrCreditCard(file_path.encode('utf-8'))
108
- ocrResDict = json.loads(ocrResult)
109
  status = "ok"
 
 
 
 
 
110
 
111
  response = jsonify({"status": status, "data": ocrResDict})
112
 
@@ -130,8 +142,12 @@ def ocr_credit_base64():
130
  file_path = os.path.abspath(save_path)
131
 
132
  ocrResult = TTVOcrCreditCard(file_path.encode('utf-8'))
133
- ocrResDict = json.loads(ocrResult)
134
  status = "ok"
 
 
 
 
 
135
 
136
  response = jsonify({"status": status, "data": ocrResDict})
137
 
@@ -162,7 +178,6 @@ def ocr_barcode():
162
  ocrResDict = json.loads(ocrResult)
163
 
164
  response = jsonify({"status": status, "data": ocrResDict})
165
- print("@@@@@", response)
166
 
167
  os.remove(file_path)
168
 
@@ -184,8 +199,12 @@ def ocr_barcode_base64():
184
  print('file_path: ', file_path)
185
 
186
  ocrResult = TTVOcrBarCode(file_path.encode('utf-8'))
187
- ocrResDict = json.loads(ocrResult)
188
  status = "ok"
 
 
 
 
 
189
 
190
  response = jsonify({"status": status, "data": ocrResDict})
191
 
 
52
 
53
 
54
  ocrResult = TTVOcrProcess(file_path1.encode('utf-8'), file_path2.encode('utf-8'))
 
55
  status = "ok"
56
+ if not ocrResult:
57
+ ocrResDict = {}
58
+ status = "error"
59
+ else:
60
+ ocrResDict = json.loads(ocrResult)
61
 
62
  if_check = ttv_if_checker(file_path1.encode('utf-8'))
63
  response = jsonify({"status": status, "data": ocrResDict, "authenticity": if_check})
 
83
  file_path = os.path.abspath(save_path)
84
 
85
  ocrResult = TTVOcrProcess(file_path.encode('utf-8'))
 
86
  status = "ok"
87
+ if not ocrResult:
88
+ ocrResDict = {}
89
+ status = "error"
90
+ else:
91
+ ocrResDict = json.loads(ocrResult)
92
 
93
  if_check = ttv_if_checker(file_path.encode('utf-8'))
94
  response = jsonify({"status": status, "data": ocrResDict, "authenticity": if_check})
 
113
  file_path = os.path.abspath(save_path)
114
 
115
  ocrResult = TTVOcrCreditCard(file_path.encode('utf-8'))
 
116
  status = "ok"
117
+ if not ocrResult:
118
+ ocrResDict = {}
119
+ status = "error"
120
+ else:
121
+ ocrResDict = json.loads(ocrResult)
122
 
123
  response = jsonify({"status": status, "data": ocrResDict})
124
 
 
142
  file_path = os.path.abspath(save_path)
143
 
144
  ocrResult = TTVOcrCreditCard(file_path.encode('utf-8'))
 
145
  status = "ok"
146
+ if not ocrResult:
147
+ ocrResDict = {}
148
+ status = "error"
149
+ else:
150
+ ocrResDict = json.loads(ocrResult)
151
 
152
  response = jsonify({"status": status, "data": ocrResDict})
153
 
 
178
  ocrResDict = json.loads(ocrResult)
179
 
180
  response = jsonify({"status": status, "data": ocrResDict})
 
181
 
182
  os.remove(file_path)
183
 
 
199
  print('file_path: ', file_path)
200
 
201
  ocrResult = TTVOcrBarCode(file_path.encode('utf-8'))
 
202
  status = "ok"
203
+ if not ocrResult:
204
+ ocrResDict = {}
205
+ status = "error"
206
+ else:
207
+ ocrResDict = json.loads(ocrResult)
208
 
209
  response = jsonify({"status": status, "data": ocrResDict})
210
 
demo.py CHANGED
@@ -61,8 +61,6 @@ def barcode_recognition(frame):
61
  files = {'image': open(frame, 'rb')}
62
  r = requests.post(url=url, files=files)
63
 
64
- print('#########', r.json())
65
-
66
  images = None
67
  resultValues = {}
68
  table_value = ""
@@ -95,7 +93,6 @@ def barcode_recognition(frame):
95
  "</table>".format(table_value=table_value))
96
 
97
  json_result = json.dumps(resultValues, indent=4)
98
- print("#############", json_result, images)
99
  return [json_result, images]
100
 
101
  def credit_recognition(frame):
@@ -162,6 +159,14 @@ with gr.Blocks() as demo:
162
  image_result_output = gr.HTML()
163
 
164
  id_recognition_button.click(idcard_recognition, inputs=[id_image_input1, id_image_input2], outputs=[id_result_output, image_result_output])
 
 
 
 
 
 
 
 
165
  with gr.TabItem("Barcode Recognition"):
166
  with gr.Row():
167
  with gr.Column(scale=3):
 
61
  files = {'image': open(frame, 'rb')}
62
  r = requests.post(url=url, files=files)
63
 
 
 
64
  images = None
65
  resultValues = {}
66
  table_value = ""
 
93
  "</table>".format(table_value=table_value))
94
 
95
  json_result = json.dumps(resultValues, indent=4)
 
96
  return [json_result, images]
97
 
98
  def credit_recognition(frame):
 
159
  image_result_output = gr.HTML()
160
 
161
  id_recognition_button.click(idcard_recognition, inputs=[id_image_input1, id_image_input2], outputs=[id_result_output, image_result_output])
162
+ gr.Markdown("## Image Examples")
163
+ gr.Examples(
164
+ examples=[['examples/11.jpg', 'examples/12.jpg'], ['examples/21.jpg', 'examples/22.jpg'], ['examples/3.jpg', None]],
165
+ inputs=[id_image_input1, id_image_input2],
166
+ outputs=[id_result_output, image_result_output],
167
+ fn=idcard_recognition,
168
+ cache_examples=True,
169
+ )
170
  with gr.TabItem("Barcode Recognition"):
171
  with gr.Row():
172
  with gr.Column(scale=3):
examples/11.jpg ADDED
examples/12.jpg ADDED
examples/21.jpg ADDED
examples/22.jpg ADDED
examples/3.jpg ADDED