cora / test_api_v2.py
tokgae's picture
Upload folder using huggingface_hub
001e827 verified
import os
from dotenv import load_dotenv
import requests
load_dotenv()
token = os.environ.get("HF_API_TOKEN") or os.environ.get("HF_TOKEN")
headers = {"Authorization": f"Bearer {token}"}
models_to_test = [
"stabilityai/stable-diffusion-xl-base-1.0",
"stabilityai/stable-diffusion-2-1",
"black-forest-labs/FLUX.1-schnell",
"runwayml/stable-diffusion-v1-5"
]
for model in models_to_test:
url = f"https://api-inference.huggingface.co/models/{model}"
print(f"\n--- Testing {model} ---")
try:
response = requests.post(url, headers=headers, json={"inputs": "A simple red apple"}, timeout=30)
print(f"Status: {response.status_code}")
print(f"Content-Type: {response.headers.get('Content-Type')}")
if response.status_code != 200:
print(f"Error: {response.text}")
elif "application/json" in response.headers.get('Content-Type', ''):
print(f"JSON Payload: {response.text}")
else:
print(f"Success: Image received ({len(response.content)} bytes)")
except Exception as e:
print(f"Exception: {e}")