Create a.py
Browse files
a.py
ADDED
|
@@ -0,0 +1,66 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
import requests
|
| 3 |
+
import os
|
| 4 |
+
from byteplussdkarkruntime import Ark
|
| 5 |
+
|
| 6 |
+
API_KEY = os.environ.get("Key", "")
|
| 7 |
+
|
| 8 |
+
def test_both(prompt_text):
|
| 9 |
+
results = []
|
| 10 |
+
|
| 11 |
+
# TEST 1: Direct BytePlus URL
|
| 12 |
+
try:
|
| 13 |
+
client_direct = Ark(
|
| 14 |
+
base_url="https://ark.ap-southeast.bytepluses.com/api/v3",
|
| 15 |
+
api_key=API_KEY,
|
| 16 |
+
timeout=10
|
| 17 |
+
)
|
| 18 |
+
result_direct = client_direct.content_generation.tasks.create(
|
| 19 |
+
model="seedance-1-5-pro-251215",
|
| 20 |
+
content=[{"type": "text", "text": prompt_text}]
|
| 21 |
+
)
|
| 22 |
+
results.append(f"✅ DIRECT: Task created {result_direct.id}")
|
| 23 |
+
except Exception as e:
|
| 24 |
+
results.append(f"❌ DIRECT: {str(e)[:100]}")
|
| 25 |
+
|
| 26 |
+
# TEST 2: Proxy URL
|
| 27 |
+
try:
|
| 28 |
+
client_proxy = Ark(
|
| 29 |
+
base_url="https://1hit.no/proxy/proxy.php",
|
| 30 |
+
api_key=API_KEY,
|
| 31 |
+
timeout=10
|
| 32 |
+
)
|
| 33 |
+
result_proxy = client_proxy.content_generation.tasks.create(
|
| 34 |
+
model="seedance-1-5-pro-251215",
|
| 35 |
+
content=[{"type": "text", "text": prompt_text}]
|
| 36 |
+
)
|
| 37 |
+
results.append(f"✅ PROXY: Task created {result_proxy.id}")
|
| 38 |
+
except Exception as e:
|
| 39 |
+
results.append(f"❌ PROXY: {str(e)[:100]}")
|
| 40 |
+
|
| 41 |
+
# TEST 3: Direct requests (no SDK)
|
| 42 |
+
try:
|
| 43 |
+
url = "https://ark.ap-southeast.bytepluses.com/api/v3/contents/generations/tasks"
|
| 44 |
+
headers = {
|
| 45 |
+
"Content-Type": "application/json",
|
| 46 |
+
"Authorization": f"Bearer {API_KEY}"
|
| 47 |
+
}
|
| 48 |
+
data = {
|
| 49 |
+
"model": "seedance-1-5-pro-251215",
|
| 50 |
+
"content": [{"type": "text", "text": prompt_text}]
|
| 51 |
+
}
|
| 52 |
+
r = requests.post(url, headers=headers, json=data, timeout=10)
|
| 53 |
+
results.append(f"✅ REQUESTS: Status {r.status_code}")
|
| 54 |
+
except Exception as e:
|
| 55 |
+
results.append(f"❌ REQUESTS: {str(e)[:100]}")
|
| 56 |
+
|
| 57 |
+
return "\n\n".join(results)
|
| 58 |
+
|
| 59 |
+
with gr.Blocks() as demo:
|
| 60 |
+
gr.Markdown("# BytePlus Connection Test")
|
| 61 |
+
prompt = gr.Textbox("test", label="Prompt")
|
| 62 |
+
btn = gr.Button("Test All")
|
| 63 |
+
output = gr.Textbox(label="Results", lines=10)
|
| 64 |
+
btn.click(fn=test_both, inputs=prompt, outputs=output)
|
| 65 |
+
|
| 66 |
+
demo.launch()
|