Sage commited on
Commit
4027f51
1 Parent(s): 8b0e4a2
Files changed (1) hide show
  1. app.py +13 -12
app.py CHANGED
@@ -32,7 +32,7 @@ def chat_gpt_image(content, context):
32
  completion = openai.ChatCompletion.create(
33
  model=gpt_model,
34
  user="1",
35
- temperature="0.5",
36
  messages=[
37
  {"role": "system", "content": prompt},
38
  {"role": "user", "content": final_content}
@@ -191,33 +191,34 @@ def batch_document(content, document_type, context, progress=gr.Progress()):
191
  combined_data = []
192
  for x in progress.tqdm(content, desc="Processing"):
193
  while True:
 
194
  try:
195
  data = json.loads(chat_gpt_document(detect_document(x),document_type,context))
196
  combined_data.append(data)
197
  break
198
- except Exception as e:
199
- logging.error(f'Retry {i+1} failed: ', e)
200
  if i < retries - 1:
201
  logging.error(f'Retrying in {timeout} seconds...')
202
  time.sleep(timeout)
203
  i += 1
204
- # except openai.error.RateLimitError:
205
- # logging.error(f'Retry {j+1} failed: openai.error.RateLimitError')
206
- # if j < retries - 1:
207
- # logging.error(f'Retrying in {timeout} seconds...')
208
- # time.sleep(timeout)
209
- # j += 1
210
  logging.info(combined_data)
211
  return save_json(combined_data, document_type)
212
 
213
  def save_json(text, filename):
214
  filename = filename+".json"
215
  with open(filename, "w", encoding='utf-8') as outfile:
216
- json.dump(text, outfile)
217
  return filename
218
 
219
- with gr.Blocks(title="Ottico OCR", css=".markdown {text-align: center;}", theme='freddyaboulton/dracula_revamped') as app:
220
- gr.Markdown("""# Ottico OCR
221
  Attach Images or Files below and convert them to Text.""", elem_classes="markdown")
222
  with gr.Tab("Scan Image"):
223
  with gr.Row():
 
32
  completion = openai.ChatCompletion.create(
33
  model=gpt_model,
34
  user="1",
35
+ temperature="0.1",
36
  messages=[
37
  {"role": "system", "content": prompt},
38
  {"role": "user", "content": final_content}
 
191
  combined_data = []
192
  for x in progress.tqdm(content, desc="Processing"):
193
  while True:
194
+ k = i+j
195
  try:
196
  data = json.loads(chat_gpt_document(detect_document(x),document_type,context))
197
  combined_data.append(data)
198
  break
199
+ except openai.error.APIConnectionError:
200
+ logging.error(f'Retry {k+1} failed: openai.error.APIConnectionError')
201
  if i < retries - 1:
202
  logging.error(f'Retrying in {timeout} seconds...')
203
  time.sleep(timeout)
204
  i += 1
205
+ except openai.error.RateLimitError:
206
+ logging.error(f'Retry {k+1} failed: openai.error.RateLimitError')
207
+ if j < retries - 1:
208
+ logging.error(f'Retrying in {timeout} seconds...')
209
+ time.sleep(timeout)
210
+ j += 1
211
  logging.info(combined_data)
212
  return save_json(combined_data, document_type)
213
 
214
  def save_json(text, filename):
215
  filename = filename+".json"
216
  with open(filename, "w", encoding='utf-8') as outfile:
217
+ json.dump(text, outfile, ensure_ascii=False)
218
  return filename
219
 
220
+ with gr.Blocks(title="Axon OCR", css=".markdown {text-align: center;}", theme='freddyaboulton/dracula_revamped') as app:
221
+ gr.Markdown("""# Axon OCR
222
  Attach Images or Files below and convert them to Text.""", elem_classes="markdown")
223
  with gr.Tab("Scan Image"):
224
  with gr.Row():