File size: 2,888 Bytes
ffa4ae8
970eef1
 
 
7e389db
4759fe1
97bea1c
970eef1
 
 
 
 
 
 
97bea1c
 
 
970eef1
 
 
97bea1c
 
 
970eef1
 
 
 
 
 
 
 
 
 
 
 
 
 
 
97bea1c
970eef1
4759fe1
97bea1c
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
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
from datetime import datetime

# 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.")
else:
    print("ℹ️ HF_TOKEN found in environment variables")

hf_organization = os.getenv("HF_ORGANIZATION")
if not hf_organization:
    print("⚠️ WARNING: HF_ORGANIZATION environment variable is not set.")
else:
    print(f"ℹ️ HF_ORGANIZATION found: {hf_organization}")

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("\n===== Application Startup at", datetime.now().strftime("%Y-%m-%d %H:%M:%S"), "=====\n")
    print(f"Initial session_files: {session_files}")
    
    # Afficher des informations détaillées sur les variables d'environnement
    print("\n===== Environment Variables Check =====")
    hf_token = os.environ.get("HF_TOKEN")
    if hf_token:
        print("✅ HF_TOKEN AVAILABLE")
    else:
        print("❌ HF_TOKEN MISSING - HuggingFace models will not work correctly")
    
    hf_organization = os.environ.get("HF_ORGANIZATION")
    if hf_organization:
        print(f"✅ HF_ORGANIZATION: {hf_organization}")
    else:
        print("❌ HF_ORGANIZATION MISSING")
    
    print("\n===== Additional Environment Variables =====")
    # Afficher d'autres variables utiles
    for env_var in ["PORT", "DEBUG", "PYTHONPATH", "VIRTUAL_ENV"]:
        value = os.environ.get(env_var)
        if value:
            print(f"ℹ️ {env_var}: {value}")
    print("=======================================\n")
    
    # 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)