Spaces:
Running
Running
Create test_api.py
Browse files- test_api.py +50 -0
test_api.py
ADDED
|
@@ -0,0 +1,50 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import requests
|
| 2 |
+
import json
|
| 3 |
+
|
| 4 |
+
# Base URL for your API
|
| 5 |
+
BASE_URL = "https://garvitcpp-recipe-rover-api.hf.space"
|
| 6 |
+
|
| 7 |
+
def test_recommend_endpoint():
|
| 8 |
+
# Endpoint URL
|
| 9 |
+
url = f"{BASE_URL}/recommend"
|
| 10 |
+
|
| 11 |
+
# Sample payload
|
| 12 |
+
payload = {
|
| 13 |
+
"category": "chicken",
|
| 14 |
+
"dietary_preference": None,
|
| 15 |
+
"ingredients": [],
|
| 16 |
+
"calories": None,
|
| 17 |
+
"time": 30,
|
| 18 |
+
"keywords": [],
|
| 19 |
+
"keywords_name": []
|
| 20 |
+
}
|
| 21 |
+
|
| 22 |
+
# Make POST request
|
| 23 |
+
response = requests.post(url, json=payload)
|
| 24 |
+
|
| 25 |
+
# Print response
|
| 26 |
+
print(f"Status Code: {response.status_code}")
|
| 27 |
+
if response.status_code == 200:
|
| 28 |
+
print("Response:")
|
| 29 |
+
print(json.dumps(response.json(), indent=2))
|
| 30 |
+
else:
|
| 31 |
+
print("Error:", response.text)
|
| 32 |
+
|
| 33 |
+
def test_form_data_endpoint():
|
| 34 |
+
# Test the GET endpoint
|
| 35 |
+
url = f"{BASE_URL}/form-data"
|
| 36 |
+
response = requests.get(url)
|
| 37 |
+
|
| 38 |
+
print(f"Status Code: {response.status_code}")
|
| 39 |
+
if response.status_code == 200:
|
| 40 |
+
print("Response:")
|
| 41 |
+
print(json.dumps(response.json(), indent=2))
|
| 42 |
+
else:
|
| 43 |
+
print("Error:", response.text)
|
| 44 |
+
|
| 45 |
+
if __name__ == "__main__":
|
| 46 |
+
print("Testing /recommend endpoint (POST):")
|
| 47 |
+
test_recommend_endpoint()
|
| 48 |
+
|
| 49 |
+
print("\nTesting /form-data endpoint (GET):")
|
| 50 |
+
test_form_data_endpoint()
|