ikechan8370 commited on
Commit
a6b9725
1 Parent(s): e08d443

Update main.py

Browse files
Files changed (1) hide show
  1. main.py +21 -5
main.py CHANGED
@@ -1,6 +1,7 @@
1
  import os
2
  from uuid import uuid4
3
 
 
4
  import torch
5
  from PIL import Image
6
  from controlnet_aux import HEDdetector
@@ -162,15 +163,30 @@ def visual_qa():
162
  result = vqa.inference(filepath, question=question)
163
  return result
164
 
165
- @app.route('/instruct-pix2pix', methods=['POST'])
166
- def InstructPix2Pix():
 
 
 
 
 
 
 
 
 
 
 
167
  file = request.files['file'] # 获取上传的文件
 
 
 
168
  filename = str(uuid4()) + '.png'
169
  filepath = os.path.join('data', 'upload', filename)
170
  file.save(filepath)
171
- output_filename = str(uuid4()) + '.png'
172
- question = request.args.get('t')
173
- result = ip2p.inference(filepath, question, output_filename)
 
174
  return result
175
 
176
  if __name__ == '__main__':
 
1
  import os
2
  from uuid import uuid4
3
 
4
+ import pytesseract
5
  import torch
6
  from PIL import Image
7
  from controlnet_aux import HEDdetector
 
163
  result = vqa.inference(filepath, question=question)
164
  return result
165
 
166
+ # @app.route('/instruct-pix2pix', methods=['POST'])
167
+ # def InstructPix2Pix():
168
+ # file = request.files['file'] # 获取上传的文件
169
+ # filename = str(uuid4()) + '.png'
170
+ # filepath = os.path.join('data', 'upload', filename)
171
+ # file.save(filepath)
172
+ # output_filename = str(uuid4()) + '.png'
173
+ # question = request.args.get('t')
174
+ # result = ip2p.inference(filepath, question, output_filename)
175
+ # return result
176
+
177
+ @app.route('/ocr', methods=['POST'])
178
+ def ocr():
179
  file = request.files['file'] # 获取上传的文件
180
+ lang = request.args.get('lang')
181
+ if lang is None:
182
+ lang = 'chi_sim+eng'
183
  filename = str(uuid4()) + '.png'
184
  filepath = os.path.join('data', 'upload', filename)
185
  file.save(filepath)
186
+ # output_filename = str(uuid4()) + '.png'
187
+
188
+ # pytesseract.pytesseract.tesseract_cmd = r'C:\Program Files\Tesseract-OCR\tesseract'
189
+ result = pytesseract.image_to_string(Image.open(filepath), lang=lang)
190
  return result
191
 
192
  if __name__ == '__main__':