Spaces:
Sleeping
Sleeping
Hermes Bot commited on
debug: add startup diagnostics to test various models and endpoints
Browse files
app.py
CHANGED
|
@@ -578,6 +578,40 @@ async def get_config():
|
|
| 578 |
# Mount static files
|
| 579 |
fastapi_app.mount("/static", StaticFiles(directory=str(STATIC_DIR)), name="static")
|
| 580 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 581 |
# Mount Gradio app at /gradio — this creates the API + MCP endpoints
|
| 582 |
gradio_blocks = create_gradio_app()
|
| 583 |
mount_gradio_app(fastapi_app, gradio_blocks, path="/gradio")
|
|
|
|
| 578 |
# Mount static files
|
| 579 |
fastapi_app.mount("/static", StaticFiles(directory=str(STATIC_DIR)), name="static")
|
| 580 |
|
| 581 |
+
@fastapi_app.on_event("startup")
|
| 582 |
+
async def run_diagnostics():
|
| 583 |
+
log.info("Running startup diagnostics for HF Inference API models...")
|
| 584 |
+
from huggingface_hub import InferenceClient
|
| 585 |
+
import os
|
| 586 |
+
token = os.environ.get("HF_TOKEN") or os.environ.get("HUGGINGFACEHUB_API_TOKEN")
|
| 587 |
+
|
| 588 |
+
models = [
|
| 589 |
+
"Qwen/Qwen2.5-1.5B-Instruct",
|
| 590 |
+
"HuggingFaceTB/SmolLM2-1.7B-Instruct",
|
| 591 |
+
"google/gemma-2-2b-it",
|
| 592 |
+
"microsoft/Phi-3.5-mini-instruct",
|
| 593 |
+
"microsoft/Phi-4-mini-instruct",
|
| 594 |
+
]
|
| 595 |
+
|
| 596 |
+
for m in models:
|
| 597 |
+
# Test 1: plain text_generation
|
| 598 |
+
try:
|
| 599 |
+
client = InferenceClient(model=m, token=token)
|
| 600 |
+
res = client.text_generation("Say hello", max_new_tokens=10)
|
| 601 |
+
log.info(f"DIAGNOSTIC: {m} (text_gen) => SUCCESS: {res.strip()}")
|
| 602 |
+
except Exception as e:
|
| 603 |
+
log.info(f"DIAGNOSTIC: {m} (text_gen) => FAIL: {str(e)[:150]}")
|
| 604 |
+
|
| 605 |
+
# Test 2: conversational
|
| 606 |
+
try:
|
| 607 |
+
client = InferenceClient(model=m, token=token)
|
| 608 |
+
# Try chat_completion but with explicit hf-inference provider if possible, or just default
|
| 609 |
+
res = client.chat_completion(messages=[{"role": "user", "content": "Say hello"}], max_tokens=10)
|
| 610 |
+
log.info(f"DIAGNOSTIC: {m} (chat) => SUCCESS: {res.choices[0].message.content.strip()}")
|
| 611 |
+
except Exception as e:
|
| 612 |
+
log.info(f"DIAGNOSTIC: {m} (chat) => FAIL: {str(e)[:150]}")
|
| 613 |
+
|
| 614 |
+
|
| 615 |
# Mount Gradio app at /gradio — this creates the API + MCP endpoints
|
| 616 |
gradio_blocks = create_gradio_app()
|
| 617 |
mount_gradio_app(fastapi_app, gradio_blocks, path="/gradio")
|