Spaces:
Running
Running
fix
Browse files
frontend/src/components/upload/GeneratedTextSection.tsx
CHANGED
|
@@ -1,4 +1,4 @@
|
|
| 1 |
-
import { Container, TextArea, Button, IconButton } from '@ifrc-go/ui';
|
| 2 |
import { DeleteBinLineIcon } from '@ifrc-go/icons';
|
| 3 |
import styles from '../../pages/UploadPage/UploadPage.module.css';
|
| 4 |
|
|
|
|
| 1 |
+
import { Container, TextArea, Button, IconButton, Spinner } from '@ifrc-go/ui';
|
| 2 |
import { DeleteBinLineIcon } from '@ifrc-go/icons';
|
| 3 |
import styles from '../../pages/UploadPage/UploadPage.module.css';
|
| 4 |
|
py_backend/app/routers/caption.py
CHANGED
|
@@ -43,6 +43,9 @@ if settings.HF_API_KEY:
|
|
| 43 |
db = SessionLocal()
|
| 44 |
try:
|
| 45 |
models = crud.get_models(db)
|
|
|
|
|
|
|
|
|
|
| 46 |
for model in models:
|
| 47 |
if (model.provider == "huggingface" and
|
| 48 |
model.model_id and
|
|
@@ -56,9 +59,20 @@ if settings.HF_API_KEY:
|
|
| 56 |
)
|
| 57 |
vlm_manager.register_service(service)
|
| 58 |
print(f"β Registered HF model: {model.m_code} -> {model.model_id}")
|
|
|
|
|
|
|
|
|
|
|
|
|
| 59 |
except Exception as e:
|
| 60 |
print(f"β Failed to register {model.m_code}: {e}")
|
| 61 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 62 |
finally:
|
| 63 |
db.close()
|
| 64 |
except Exception as e:
|
|
@@ -66,7 +80,7 @@ if settings.HF_API_KEY:
|
|
| 66 |
import traceback
|
| 67 |
traceback.print_exc()
|
| 68 |
else:
|
| 69 |
-
print("β Hugging Face services not configured")
|
| 70 |
|
| 71 |
print(f"β Available models: {', '.join(vlm_manager.get_available_models())}")
|
| 72 |
print(f"β Total services: {len(vlm_manager.services)}")
|
|
|
|
| 43 |
db = SessionLocal()
|
| 44 |
try:
|
| 45 |
models = crud.get_models(db)
|
| 46 |
+
registered_count = 0
|
| 47 |
+
failed_count = 0
|
| 48 |
+
|
| 49 |
for model in models:
|
| 50 |
if (model.provider == "huggingface" and
|
| 51 |
model.model_id and
|
|
|
|
| 59 |
)
|
| 60 |
vlm_manager.register_service(service)
|
| 61 |
print(f"β Registered HF model: {model.m_code} -> {model.model_id}")
|
| 62 |
+
registered_count += 1
|
| 63 |
+
except ValueError as e:
|
| 64 |
+
print(f"β Failed to register {model.m_code}: Configuration error - {e}")
|
| 65 |
+
failed_count += 1
|
| 66 |
except Exception as e:
|
| 67 |
print(f"β Failed to register {model.m_code}: {e}")
|
| 68 |
+
failed_count += 1
|
| 69 |
+
|
| 70 |
+
if registered_count > 0:
|
| 71 |
+
print(f"β Hugging Face services registered: {registered_count} models successfully")
|
| 72 |
+
if failed_count > 0:
|
| 73 |
+
print(f"β οΈ Hugging Face services: {failed_count} models failed to register")
|
| 74 |
+
if registered_count == 0 and failed_count == 0:
|
| 75 |
+
print("β No Hugging Face models found in database")
|
| 76 |
finally:
|
| 77 |
db.close()
|
| 78 |
except Exception as e:
|
|
|
|
| 80 |
import traceback
|
| 81 |
traceback.print_exc()
|
| 82 |
else:
|
| 83 |
+
print("β Hugging Face services not configured (HF_API_KEY not set)")
|
| 84 |
|
| 85 |
print(f"β Available models: {', '.join(vlm_manager.get_available_models())}")
|
| 86 |
print(f"β Total services: {len(vlm_manager.services)}")
|
py_backend/app/services/huggingface_service.py
CHANGED
|
@@ -286,6 +286,11 @@ class ProvidersGenericVLMService(HuggingFaceService):
|
|
| 286 |
ProvidersGenericVLMService(HF_TOKEN, "Qwen/Qwen2.5-VL-32B-Instruct", "QWEN2_5_VL_32B")
|
| 287 |
"""
|
| 288 |
def __init__(self, api_key: str, model_id: str, public_name: str | None = None):
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 289 |
# Use the default HuggingFace providers URL
|
| 290 |
providers_url = "https://api-inference.huggingface.co/providers/openai"
|
| 291 |
super().__init__(api_key, model_id, providers_url)
|
|
|
|
| 286 |
ProvidersGenericVLMService(HF_TOKEN, "Qwen/Qwen2.5-VL-32B-Instruct", "QWEN2_5_VL_32B")
|
| 287 |
"""
|
| 288 |
def __init__(self, api_key: str, model_id: str, public_name: str | None = None):
|
| 289 |
+
if not api_key:
|
| 290 |
+
raise ValueError("HF_API_KEY is required for Hugging Face models")
|
| 291 |
+
if not model_id:
|
| 292 |
+
raise ValueError("model_id is required for Hugging Face models")
|
| 293 |
+
|
| 294 |
# Use the default HuggingFace providers URL
|
| 295 |
providers_url = "https://api-inference.huggingface.co/providers/openai"
|
| 296 |
super().__init__(api_key, model_id, providers_url)
|
py_backend/debug_hf_models.py
ADDED
|
@@ -0,0 +1,132 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/usr/bin/env python3
|
| 2 |
+
"""
|
| 3 |
+
Debug script to diagnose Hugging Face model registration issues.
|
| 4 |
+
Run this script to check API key validity and model availability.
|
| 5 |
+
"""
|
| 6 |
+
|
| 7 |
+
import os
|
| 8 |
+
import sys
|
| 9 |
+
import asyncio
|
| 10 |
+
import aiohttp
|
| 11 |
+
import json
|
| 12 |
+
from typing import Dict, Any
|
| 13 |
+
|
| 14 |
+
# Add the current directory to Python path
|
| 15 |
+
sys.path.append(os.path.dirname(os.path.abspath(__file__)))
|
| 16 |
+
|
| 17 |
+
from app.config import settings
|
| 18 |
+
from app.database import SessionLocal
|
| 19 |
+
from app import crud
|
| 20 |
+
|
| 21 |
+
async def test_hf_api_key(api_key: str) -> Dict[str, Any]:
|
| 22 |
+
"""Test if the Hugging Face API key is valid"""
|
| 23 |
+
headers = {
|
| 24 |
+
"Authorization": f"Bearer {api_key}",
|
| 25 |
+
"Content-Type": "application/json",
|
| 26 |
+
}
|
| 27 |
+
|
| 28 |
+
# Test with a simple model list request
|
| 29 |
+
test_url = "https://api-inference.huggingface.co/models"
|
| 30 |
+
|
| 31 |
+
try:
|
| 32 |
+
async with aiohttp.ClientSession() as session:
|
| 33 |
+
async with session.get(test_url, headers=headers, timeout=30) as resp:
|
| 34 |
+
if resp.status == 200:
|
| 35 |
+
return {"valid": True, "message": "API key is valid"}
|
| 36 |
+
elif resp.status == 401:
|
| 37 |
+
return {"valid": False, "message": "API key is invalid or expired"}
|
| 38 |
+
else:
|
| 39 |
+
return {"valid": False, "message": f"API test failed with status {resp.status}"}
|
| 40 |
+
except Exception as e:
|
| 41 |
+
return {"valid": False, "message": f"API test failed: {str(e)}"}
|
| 42 |
+
|
| 43 |
+
async def test_model_availability(api_key: str, model_id: str) -> Dict[str, Any]:
|
| 44 |
+
"""Test if a specific model is available"""
|
| 45 |
+
headers = {
|
| 46 |
+
"Authorization": f"Bearer {api_key}",
|
| 47 |
+
"Content-Type": "application/json",
|
| 48 |
+
}
|
| 49 |
+
|
| 50 |
+
# Test with a simple text generation request
|
| 51 |
+
test_url = f"https://api-inference.huggingface.co/models/{model_id}"
|
| 52 |
+
payload = {
|
| 53 |
+
"inputs": "Hello, how are you?",
|
| 54 |
+
"parameters": {"max_new_tokens": 10}
|
| 55 |
+
}
|
| 56 |
+
|
| 57 |
+
try:
|
| 58 |
+
async with aiohttp.ClientSession() as session:
|
| 59 |
+
async with session.post(test_url, headers=headers, json=payload, timeout=30) as resp:
|
| 60 |
+
if resp.status == 200:
|
| 61 |
+
return {"available": True, "message": "Model is available"}
|
| 62 |
+
elif resp.status == 404:
|
| 63 |
+
return {"available": False, "message": "Model not found"}
|
| 64 |
+
elif resp.status == 503:
|
| 65 |
+
return {"available": False, "message": "Model is loading or unavailable"}
|
| 66 |
+
else:
|
| 67 |
+
return {"available": False, "message": f"Model test failed with status {resp.status}"}
|
| 68 |
+
except Exception as e:
|
| 69 |
+
return {"available": False, "message": f"Model test failed: {str(e)}"}
|
| 70 |
+
|
| 71 |
+
async def main():
|
| 72 |
+
"""Main diagnostic function"""
|
| 73 |
+
print("π Hugging Face Model Diagnostic Tool")
|
| 74 |
+
print("=" * 50)
|
| 75 |
+
|
| 76 |
+
# Check if API key is set
|
| 77 |
+
if not settings.HF_API_KEY:
|
| 78 |
+
print("β HF_API_KEY is not set in environment variables")
|
| 79 |
+
print(" Please set HF_API_KEY to your Hugging Face API token")
|
| 80 |
+
return
|
| 81 |
+
|
| 82 |
+
print(f"β
HF_API_KEY is set (length: {len(settings.HF_API_KEY)})")
|
| 83 |
+
|
| 84 |
+
# Test API key validity
|
| 85 |
+
print("\nπ Testing API key validity...")
|
| 86 |
+
api_test = await test_hf_api_key(settings.HF_API_KEY)
|
| 87 |
+
if api_test["valid"]:
|
| 88 |
+
print(f"β
{api_test['message']}")
|
| 89 |
+
else:
|
| 90 |
+
print(f"β {api_test['message']}")
|
| 91 |
+
print(" Please check your Hugging Face API token at https://huggingface.co/settings/tokens")
|
| 92 |
+
return
|
| 93 |
+
|
| 94 |
+
# Get models from database
|
| 95 |
+
print("\nπ Checking models in database...")
|
| 96 |
+
db = SessionLocal()
|
| 97 |
+
try:
|
| 98 |
+
models = crud.get_models(db)
|
| 99 |
+
hf_models = [m for m in models if m.provider == "huggingface" and m.model_id]
|
| 100 |
+
|
| 101 |
+
if not hf_models:
|
| 102 |
+
print("β οΈ No Hugging Face models found in database")
|
| 103 |
+
return
|
| 104 |
+
|
| 105 |
+
print(f"β
Found {len(hf_models)} Hugging Face models in database:")
|
| 106 |
+
for model in hf_models:
|
| 107 |
+
print(f" - {model.m_code}: {model.model_id}")
|
| 108 |
+
|
| 109 |
+
# Test each model
|
| 110 |
+
print("\nπ§ͺ Testing model availability...")
|
| 111 |
+
for model in hf_models:
|
| 112 |
+
print(f"\nTesting {model.m_code} ({model.model_id})...")
|
| 113 |
+
model_test = await test_model_availability(settings.HF_API_KEY, model.model_id)
|
| 114 |
+
|
| 115 |
+
if model_test["available"]:
|
| 116 |
+
print(f" β
{model_test['message']}")
|
| 117 |
+
else:
|
| 118 |
+
print(f" β {model_test['message']}")
|
| 119 |
+
|
| 120 |
+
finally:
|
| 121 |
+
db.close()
|
| 122 |
+
|
| 123 |
+
print("\n" + "=" * 50)
|
| 124 |
+
print("π‘ Troubleshooting Tips:")
|
| 125 |
+
print("1. Check your Hugging Face API token at https://huggingface.co/settings/tokens")
|
| 126 |
+
print("2. Ensure your token has 'read' permissions")
|
| 127 |
+
print("3. Some models may require special access or may be temporarily unavailable")
|
| 128 |
+
print("4. Check model availability at https://huggingface.co/models")
|
| 129 |
+
print("5. Network issues can cause connection failures")
|
| 130 |
+
|
| 131 |
+
if __name__ == "__main__":
|
| 132 |
+
asyncio.run(main())
|