dlxj commited on
Commit ·
4f3f873
1
Parent(s): 152d6c3
add post.py
Browse files- .gitignore +1 -0
- post.py +46 -0
.gitignore
CHANGED
|
@@ -1 +1,2 @@
|
|
| 1 |
out.json
|
|
|
|
|
|
| 1 |
out.json
|
| 2 |
+
.vscode/settings.json
|
post.py
ADDED
|
@@ -0,0 +1,46 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import requests
|
| 2 |
+
import base64
|
| 3 |
+
import json
|
| 4 |
+
import os
|
| 5 |
+
|
| 6 |
+
def test_ppocr():
|
| 7 |
+
# Configuration
|
| 8 |
+
url = "http://127.0.0.1:8889/ppocr"
|
| 9 |
+
image_path = r"e:\huggingface_echodict\t\PPOCRLLM\data\0022.jpg"
|
| 10 |
+
|
| 11 |
+
# Check if image exists
|
| 12 |
+
if not os.path.exists(image_path):
|
| 13 |
+
print(f"Error: Image file not found at {image_path}")
|
| 14 |
+
return
|
| 15 |
+
|
| 16 |
+
try:
|
| 17 |
+
# Read and encode image
|
| 18 |
+
with open(image_path, "rb") as image_file:
|
| 19 |
+
base64_str = base64.b64encode(image_file.read()).decode('utf-8')
|
| 20 |
+
|
| 21 |
+
# Prepare payload
|
| 22 |
+
payload = {
|
| 23 |
+
"img": base64_str
|
| 24 |
+
}
|
| 25 |
+
headers = {
|
| 26 |
+
"Content-Type": "application/json"
|
| 27 |
+
}
|
| 28 |
+
|
| 29 |
+
# Send request
|
| 30 |
+
print(f"Sending POST request to {url}...")
|
| 31 |
+
response = requests.post(url, json=payload, headers=headers)
|
| 32 |
+
|
| 33 |
+
# Print result
|
| 34 |
+
print(f"Status Code: {response.status_code}")
|
| 35 |
+
try:
|
| 36 |
+
print("Response JSON:")
|
| 37 |
+
print(json.dumps(response.json(), indent=4, ensure_ascii=False))
|
| 38 |
+
except json.JSONDecodeError:
|
| 39 |
+
print("Response Text:")
|
| 40 |
+
print(response.text)
|
| 41 |
+
|
| 42 |
+
except Exception as e:
|
| 43 |
+
print(f"An error occurred: {e}")
|
| 44 |
+
|
| 45 |
+
if __name__ == "__main__":
|
| 46 |
+
test_ppocr()
|