Sage
commited on
Commit
•
cfb190d
1
Parent(s):
c6dfe38
Add error changes
Browse files
app.py
CHANGED
@@ -48,13 +48,14 @@ def batch_document(content, document_type, context, progress = gr.Progress()):
|
|
48 |
|
49 |
if progress == "None":
|
50 |
for x in content:
|
51 |
-
retries =
|
52 |
-
timeout =
|
53 |
i = 0
|
54 |
while True:
|
55 |
try:
|
56 |
data = json.loads(chat_gpt_document(detect_document(x),document_type,context))
|
57 |
combined_data.append(data)
|
|
|
58 |
break
|
59 |
except (openai.error.APIConnectionError, openai.error.AuthenticationError, openai.error.RateLimitError, HttpResponseError, requests.exceptions.RequestException) as e:
|
60 |
logging.error(f'Retry {i+1} failed: {e}')
|
@@ -76,6 +77,7 @@ def batch_document(content, document_type, context, progress = gr.Progress()):
|
|
76 |
try:
|
77 |
data = json.loads(chat_gpt_document(detect_document(x),document_type,context))
|
78 |
combined_data.append(data)
|
|
|
79 |
break
|
80 |
except (openai.error.APIConnectionError, openai.error.AuthenticationError, openai.error.RateLimitError, HttpResponseError, requests.exceptions.RequestException) as e:
|
81 |
logging.error(f'Retry {i+1} failed: {e}')
|
@@ -92,10 +94,42 @@ def batch_document(content, document_type, context, progress = gr.Progress()):
|
|
92 |
if document_type == "":
|
93 |
document_type = "error"
|
94 |
return save_json(combined_data, document_type)
|
|
|
95 |
def image(content, context):
|
96 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
97 |
def document(content, document_type, context):
|
98 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
99 |
|
100 |
with gr.Blocks(title="Axon OCR", css=".markdown {text-align: center;}") as app:
|
101 |
gr.Markdown("""# Axon OCR
|
|
|
48 |
|
49 |
if progress == "None":
|
50 |
for x in content:
|
51 |
+
retries = 3
|
52 |
+
timeout = 3
|
53 |
i = 0
|
54 |
while True:
|
55 |
try:
|
56 |
data = json.loads(chat_gpt_document(detect_document(x),document_type,context))
|
57 |
combined_data.append(data)
|
58 |
+
i = 0
|
59 |
break
|
60 |
except (openai.error.APIConnectionError, openai.error.AuthenticationError, openai.error.RateLimitError, HttpResponseError, requests.exceptions.RequestException) as e:
|
61 |
logging.error(f'Retry {i+1} failed: {e}')
|
|
|
77 |
try:
|
78 |
data = json.loads(chat_gpt_document(detect_document(x),document_type,context))
|
79 |
combined_data.append(data)
|
80 |
+
i = 0
|
81 |
break
|
82 |
except (openai.error.APIConnectionError, openai.error.AuthenticationError, openai.error.RateLimitError, HttpResponseError, requests.exceptions.RequestException) as e:
|
83 |
logging.error(f'Retry {i+1} failed: {e}')
|
|
|
94 |
if document_type == "":
|
95 |
document_type = "error"
|
96 |
return save_json(combined_data, document_type)
|
97 |
+
|
98 |
def image(content, context):
|
99 |
+
retries = 3
|
100 |
+
timeout = 3
|
101 |
+
i = 0
|
102 |
+
while True:
|
103 |
+
try:
|
104 |
+
data = chat_gpt_image(detect_image(content), context)
|
105 |
+
break
|
106 |
+
except (openai.error.APIConnectionError, openai.error.AuthenticationError, openai.error.RateLimitError, HttpResponseError, requests.exceptions.RequestException) as e:
|
107 |
+
logging.error(f'Retry {i+1} failed: {e}')
|
108 |
+
if i < retries - 1:
|
109 |
+
logging.error(f'Retrying in {timeout} seconds...')
|
110 |
+
time.sleep(timeout)
|
111 |
+
i += 1
|
112 |
+
else:
|
113 |
+
break
|
114 |
+
return data
|
115 |
+
|
116 |
def document(content, document_type, context):
|
117 |
+
retries = 3
|
118 |
+
timeout = 3
|
119 |
+
i = 0
|
120 |
+
while True:
|
121 |
+
try:
|
122 |
+
data = chat_gpt_document(detect_document(content),document_type,context)
|
123 |
+
break
|
124 |
+
except (openai.error.APIConnectionError, openai.error.AuthenticationError, openai.error.RateLimitError, HttpResponseError, requests.exceptions.RequestException) as e:
|
125 |
+
logging.error(f'Retry {i+1} failed: {e}')
|
126 |
+
if i < retries - 1:
|
127 |
+
logging.error(f'Retrying in {timeout} seconds...')
|
128 |
+
time.sleep(timeout)
|
129 |
+
i += 1
|
130 |
+
else:
|
131 |
+
break
|
132 |
+
return data
|
133 |
|
134 |
with gr.Blocks(title="Axon OCR", css=".markdown {text-align: center;}") as app:
|
135 |
gr.Markdown("""# Axon OCR
|