Spaces:
Sleeping
Sleeping
File size: 1,568 Bytes
842ca78 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 |
import os
import requests
import json
from dotenv import load_dotenv
load_dotenv()
api_key = os.getenv("HF_TOKEN")
model = "Qwen/Qwen2-VL-7B-Instruct"
# Update URL to router
url = f"https://router.huggingface.co/models/{model}"
headers = {"Authorization": f"Bearer {api_key}"}
print(f"Testing URL: {url}")
# Test 1: Simple text generation payload (inputs string)
data_text = {
"inputs": "Hello",
"parameters": {"max_new_tokens": 50}
}
print("\n--- Test 1: Text Generation (inputs string) ---")
response = requests.post(url, headers=headers, json=data_text)
print(f"Status: {response.status_code}")
print("Response:", response.text)
# Test 2: VQA format
data_vqa = {
"inputs": {
"image": "https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/transformers/tasks/car.jpg?download=true",
"question": "What is in this image?"
}
}
print("\n--- Test 2: VQA Format ---")
response = requests.post(url, headers=headers, json=data_vqa)
print(f"Status: {response.status_code}")
print("Response:", response.text)
# Test 3: Chat Completions API (OpenAI style)
url_chat = f"https://router.huggingface.co/models/{model}/v1/chat/completions"
print(f"\nTesting URL: {url_chat}")
data_chat = {
"model": model, # Sometimes required in body
"messages": [
{"role": "user", "content": "Hello"}
],
"max_tokens": 50
}
print("\n--- Test 3: Chat Completion ---")
response = requests.post(url_chat, headers=headers, json=data_chat)
print(f"Status: {response.status_code}")
print("Response:", response.text)
|