Spaces:
Sleeping
Sleeping
Create test_client.py
Browse files- test_client.py +19 -0
test_client.py
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# test_client.py
|
| 2 |
+
import requests
|
| 3 |
+
|
| 4 |
+
# Test the FastAPI endpoint
|
| 5 |
+
response = requests.post(
|
| 6 |
+
"http://localhost:7860/visualize/natural",
|
| 7 |
+
files={"file": open("data.xlsx", "rb")}, # Replace "data.xlsx" with your file
|
| 8 |
+
data={"prompt": "Show sales over time", "return_type": "base64"}
|
| 9 |
+
)
|
| 10 |
+
|
| 11 |
+
# Print the JSON response (contains Base64 image)
|
| 12 |
+
print(response.json())
|
| 13 |
+
|
| 14 |
+
# To save the image (optional):
|
| 15 |
+
if "image" in response.json():
|
| 16 |
+
import base64
|
| 17 |
+
image_data = response.json()["image"].split(",")[1] # Remove header
|
| 18 |
+
with open("plot.png", "wb") as f:
|
| 19 |
+
f.write(base64.b64decode(image_data))
|