Spaces:
Runtime error
Runtime error
linjieccc
commited on
Commit
•
907cc24
1
Parent(s):
3d14c7f
Update app.py
Browse files
app.py
CHANGED
@@ -177,17 +177,17 @@ def load_document(path):
|
|
177 |
images_list.append(img_np)
|
178 |
else:
|
179 |
image = Image.open(b)
|
180 |
-
images_list = [image.convert("RGB")]
|
181 |
return images_list
|
182 |
|
183 |
def process_path(path):
|
184 |
error = None
|
185 |
if path:
|
186 |
try:
|
187 |
-
|
188 |
return (
|
189 |
path,
|
190 |
-
gr.update(visible=True, value=
|
191 |
gr.update(visible=True),
|
192 |
gr.update(visible=False, value=None),
|
193 |
gr.update(visible=False, value=None),
|
@@ -221,9 +221,9 @@ def process_upload(file):
|
|
221 |
)
|
222 |
|
223 |
|
224 |
-
def
|
225 |
-
|
226 |
-
|
227 |
return base64_str
|
228 |
|
229 |
|
@@ -236,8 +236,11 @@ def process_prompt(prompt, document, lang="ch"):
|
|
236 |
access_token = os.environ['token']
|
237 |
|
238 |
url = f"https://aip.baidubce.com/rpc/2.0/nlp-itec/poc/docprompt?access_token={access_token}"
|
|
|
|
|
|
|
239 |
|
240 |
-
r = requests.post(url, json={"doc":
|
241 |
response = r.json()
|
242 |
|
243 |
predictions = response['result']
|
@@ -495,4 +498,5 @@ with gr.Blocks(css=CSS) as demo:
|
|
495 |
|
496 |
|
497 |
if __name__ == "__main__":
|
498 |
-
demo.launch(enable_queue=False)
|
|
|
|
177 |
images_list.append(img_np)
|
178 |
else:
|
179 |
image = Image.open(b)
|
180 |
+
images_list = [np.array(image.convert("RGB"))]
|
181 |
return images_list
|
182 |
|
183 |
def process_path(path):
|
184 |
error = None
|
185 |
if path:
|
186 |
try:
|
187 |
+
images_list = load_document(path)
|
188 |
return (
|
189 |
path,
|
190 |
+
gr.update(visible=True, value=images_list),
|
191 |
gr.update(visible=True),
|
192 |
gr.update(visible=False, value=None),
|
193 |
gr.update(visible=False, value=None),
|
|
|
221 |
)
|
222 |
|
223 |
|
224 |
+
def np2base64(image_np):
|
225 |
+
image = cv2.imencode('.jpg', image_np)[1]
|
226 |
+
base64_str = str(base64.b64encode(image))[2:-1]
|
227 |
return base64_str
|
228 |
|
229 |
|
|
|
236 |
access_token = os.environ['token']
|
237 |
|
238 |
url = f"https://aip.baidubce.com/rpc/2.0/nlp-itec/poc/docprompt?access_token={access_token}"
|
239 |
+
|
240 |
+
image_list = load_document(document)
|
241 |
+
base64_str = np2base64(image_list[0])
|
242 |
|
243 |
+
r = requests.post(url, json={"doc": base64_str, "prompt": [prompt], "lang": lang})
|
244 |
response = r.json()
|
245 |
|
246 |
predictions = response['result']
|
|
|
498 |
|
499 |
|
500 |
if __name__ == "__main__":
|
501 |
+
# demo.launch(enable_queue=False)
|
502 |
+
demo.launch(enable_queue=True, server_name="10.21.226.184", server_port=8072, share=False)
|