Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -8,6 +8,7 @@ from pydantic import BaseModel
|
|
| 8 |
from typing import List, Dict
|
| 9 |
import uvicorn
|
| 10 |
import json
|
|
|
|
| 11 |
|
| 12 |
# Initialiser l'application FastAPI
|
| 13 |
app = FastAPI()
|
|
@@ -89,6 +90,9 @@ async def mock_endpoint(payload: MockRequest):
|
|
| 89 |
Endpoint API qui prend un string et un secret, vérifie le secret,
|
| 90 |
puis transmet via WebSocket, attend une réponse et la retourne.
|
| 91 |
"""
|
|
|
|
|
|
|
|
|
|
| 92 |
try:
|
| 93 |
input_string = payload.parameter
|
| 94 |
selected_model = payload.model
|
|
@@ -132,6 +136,11 @@ async def mock_endpoint(payload: MockRequest):
|
|
| 132 |
print(f"Réponse reçue du WebSocket: '{websocket_response}'")
|
| 133 |
return {"response_from_client": websocket_response}
|
| 134 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 135 |
except asyncio.TimeoutError:
|
| 136 |
print("Timeout: Aucune réponse du client WebSocket.")
|
| 137 |
raise HTTPException(status_code=408, detail="Timeout: Le client n'a pas répondu à temps.")
|
|
|
|
| 8 |
from typing import List, Dict
|
| 9 |
import uvicorn
|
| 10 |
import json
|
| 11 |
+
import time
|
| 12 |
|
| 13 |
# Initialiser l'application FastAPI
|
| 14 |
app = FastAPI()
|
|
|
|
| 90 |
Endpoint API qui prend un string et un secret, vérifie le secret,
|
| 91 |
puis transmet via WebSocket, attend une réponse et la retourne.
|
| 92 |
"""
|
| 93 |
+
|
| 94 |
+
start_time = time.monotonic()
|
| 95 |
+
|
| 96 |
try:
|
| 97 |
input_string = payload.parameter
|
| 98 |
selected_model = payload.model
|
|
|
|
| 136 |
print(f"Réponse reçue du WebSocket: '{websocket_response}'")
|
| 137 |
return {"response_from_client": websocket_response}
|
| 138 |
|
| 139 |
+
|
| 140 |
+
end_time = time.monotonic()
|
| 141 |
+
duration = end_time - start_time
|
| 142 |
+
print(f"Requête complétée en {duration:.2f} secondes.")
|
| 143 |
+
|
| 144 |
except asyncio.TimeoutError:
|
| 145 |
print("Timeout: Aucune réponse du client WebSocket.")
|
| 146 |
raise HTTPException(status_code=408, detail="Timeout: Le client n'a pas répondu à temps.")
|