Spaces:
Running
on
CPU Upgrade
Running
on
CPU Upgrade
File size: 1,864 Bytes
ffa4ae8 970eef1 7e389db 4759fe1 970eef1 4759fe1 970eef1 |
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 |
from fastapi import FastAPI, UploadFile, File, Form, Request, HTTPException
from fastapi.middleware.cors import CORSMiddleware
import os
from dotenv import load_dotenv
from routes import routers, session_files, active_tasks, benchmark
from tasks.get_available_model_provider import test_models
# Load environment variables from .env file
load_dotenv()
# Verify environment variables are loaded
hf_token = os.getenv("HF_TOKEN")
if not hf_token:
print("Warning: HF_TOKEN environment variable is not set. Make sure it's defined in your .env file.")
hf_organization = os.getenv("HF_ORGANIZATION")
if not hf_organization:
print("Warning: HF_ORGANIZATION environment variable is not set. Make sure it's defined in your .env file.")
app = FastAPI(title="Yourbench API")
# Activer CORS pour permettre les requêtes depuis le frontend
app.add_middleware(
CORSMiddleware,
allow_origins=["*"], # Dans un environnement de production, spécifiez les origines exactes
allow_credentials=True,
allow_methods=["*"],
allow_headers=["*"],
)
# Ajouter un gestionnaire d'événements pour afficher les session_files au démarrage
@app.on_event("startup")
async def startup_event():
print("Application startup")
print(f"Initial session_files: {session_files}")
# Tester les modèles au démarrage et afficher les résultats
print("===== Testing model availability at startup =====")
test_results = test_models(verbose=True)
print("===== Model testing completed =====")
if test_results["working_model"]:
print(f"✅ Found working model: {test_results['working_model']} with provider: {test_results['provider']}")
else:
print("❌ WARNING: No working models found. The application might not function correctly!")
# Enregistrer toutes les routes
for router in routers:
app.include_router(router) |