Bobholamovic
commited on
Commit
·
ee1547b
1
Parent(s):
ea978b8
Update
Browse files
app.py
CHANGED
|
@@ -20,6 +20,8 @@ def inference(img):
|
|
| 20 |
"Content-Type": "application/json",
|
| 21 |
}
|
| 22 |
|
|
|
|
|
|
|
| 23 |
response = requests.post(
|
| 24 |
API_URL,
|
| 25 |
json={
|
|
@@ -31,19 +33,24 @@ def inference(img):
|
|
| 31 |
headers=headers,
|
| 32 |
timeout=1000,
|
| 33 |
)
|
|
|
|
| 34 |
response.raise_for_status()
|
| 35 |
|
| 36 |
result = response.json()
|
| 37 |
ocr_img_url = result["result"]["ocrResults"][0]["ocrImage"]
|
| 38 |
|
|
|
|
| 39 |
response = requests.get(ocr_img_url, timeout=10)
|
|
|
|
| 40 |
response.raise_for_status()
|
| 41 |
-
|
|
|
|
|
|
|
| 42 |
|
| 43 |
|
| 44 |
title = "PP-OCRv5"
|
| 45 |
description = """
|
| 46 |
-
- Gradio demo for PP-OCRv5.
|
| 47 |
- To use it, simply upload your image, or click one of the examples to load them. Read more at the links below.
|
| 48 |
- [Docs](https://paddlepaddle.github.io/PaddleOCR/), [Github Repository](https://github.com/PaddlePaddle/PaddleOCR).
|
| 49 |
"""
|
|
@@ -62,10 +69,8 @@ examples = [
|
|
| 62 |
css = ".output_image, .input_image {height: 40rem !important; width: 100% !important;}"
|
| 63 |
gr.Interface(
|
| 64 |
inference,
|
| 65 |
-
|
| 66 |
-
|
| 67 |
-
],
|
| 68 |
-
gr.Image(type="pil", label="Output"),
|
| 69 |
title=title,
|
| 70 |
description=description,
|
| 71 |
examples=examples,
|
|
|
|
| 20 |
"Content-Type": "application/json",
|
| 21 |
}
|
| 22 |
|
| 23 |
+
import time
|
| 24 |
+
t1 = time.time()
|
| 25 |
response = requests.post(
|
| 26 |
API_URL,
|
| 27 |
json={
|
|
|
|
| 33 |
headers=headers,
|
| 34 |
timeout=1000,
|
| 35 |
)
|
| 36 |
+
print("t1", time.time()-t1, flush=True)
|
| 37 |
response.raise_for_status()
|
| 38 |
|
| 39 |
result = response.json()
|
| 40 |
ocr_img_url = result["result"]["ocrResults"][0]["ocrImage"]
|
| 41 |
|
| 42 |
+
t2 = time.time()
|
| 43 |
response = requests.get(ocr_img_url, timeout=10)
|
| 44 |
+
print("t2", time.time()-t2, flush=True)
|
| 45 |
response.raise_for_status()
|
| 46 |
+
ocr_img_base64 = Image.open(io.BytesIO(response.content))
|
| 47 |
+
|
| 48 |
+
return ocr_img_base64, result["result"]["ocrResults"][0]["prunedResult"]
|
| 49 |
|
| 50 |
|
| 51 |
title = "PP-OCRv5"
|
| 52 |
description = """
|
| 53 |
+
- Gradio demo for PP-OCRv5. PP-OCRv5 is the new generation text recognition solution of PP-OCR, focusing on multi-scenario and multi-text type recognition. In terms of text types, PP-OCRv5 supports 5 major mainstream text types: Simplified Chinese, Chinese Pinyin, Traditional Chinese, English, and Japanese. For scenarios, PP-OCRv5 has upgraded recognition capabilities for challenging scenarios such as complex Chinese and English handwriting, vertical text, and uncommon characters.
|
| 54 |
- To use it, simply upload your image, or click one of the examples to load them. Read more at the links below.
|
| 55 |
- [Docs](https://paddlepaddle.github.io/PaddleOCR/), [Github Repository](https://github.com/PaddlePaddle/PaddleOCR).
|
| 56 |
"""
|
|
|
|
| 69 |
css = ".output_image, .input_image {height: 40rem !important; width: 100% !important;}"
|
| 70 |
gr.Interface(
|
| 71 |
inference,
|
| 72 |
+
gr.Image(type="pil", label="Input Image"),
|
| 73 |
+
[gr.Image(type="pil", label="Output Image"), gr.JSON(label="Output JSON", show_label=True)],
|
|
|
|
|
|
|
| 74 |
title=title,
|
| 75 |
description=description,
|
| 76 |
examples=examples,
|