Update handler.py
Browse files- handler.py +56 -1
handler.py
CHANGED
|
@@ -474,4 +474,59 @@ class EndpointHandler:
|
|
| 474 |
return get_model_info()
|
| 475 |
|
| 476 |
if __name__ == "__main__":
|
| 477 |
-
print("Handler ready (Demo Parity + Style Hint + whitespace post-process). Use `EndpointHandler` or `query`.")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 474 |
return get_model_info()
|
| 475 |
|
| 476 |
if __name__ == "__main__":
|
| 477 |
+
print("Handler ready (Demo Parity + Style Hint + whitespace post-process). Use `EndpointHandler` or `query`.")
|
| 478 |
+
|
| 479 |
+
|
| 480 |
+
# ===================== Minimal FastAPI Wrapper =====================
|
| 481 |
+
try:
|
| 482 |
+
from fastapi import FastAPI, Body
|
| 483 |
+
from pydantic import BaseModel
|
| 484 |
+
from typing import Any, Dict
|
| 485 |
+
FASTAPI_AVAILABLE = True
|
| 486 |
+
except Exception as e:
|
| 487 |
+
FASTAPI_AVAILABLE = False
|
| 488 |
+
print(f"[WARN] fastapi/pydantic not available: {e}")
|
| 489 |
+
|
| 490 |
+
if FASTAPI_AVAILABLE:
|
| 491 |
+
app = FastAPI(title="PULSE ECG Handler API", version="1.0.0")
|
| 492 |
+
|
| 493 |
+
class QueryIn(BaseModel):
|
| 494 |
+
# Hugging Face Endpoint tarzı payload ile uyumlu
|
| 495 |
+
message: str | None = None
|
| 496 |
+
query: str | None = None
|
| 497 |
+
prompt: str | None = None
|
| 498 |
+
istem: str | None = None
|
| 499 |
+
image: str | Dict[str, Any] | None = None
|
| 500 |
+
image_url: str | None = None
|
| 501 |
+
img: str | None = None
|
| 502 |
+
temperature: float | None = None
|
| 503 |
+
top_p: float | None = None
|
| 504 |
+
max_output_tokens: int | None = None
|
| 505 |
+
max_new_tokens: int | None = None
|
| 506 |
+
max_tokens: int | None = None
|
| 507 |
+
repetition_penalty: float | None = None
|
| 508 |
+
conv_mode: str | None = None
|
| 509 |
+
det_seed: int | None = None
|
| 510 |
+
|
| 511 |
+
@app.on_event("startup")
|
| 512 |
+
async def _startup():
|
| 513 |
+
global model_initialized
|
| 514 |
+
if not model_initialized:
|
| 515 |
+
model_initialized = initialize_model()
|
| 516 |
+
print(f"[startup] model_initialized={model_initialized}")
|
| 517 |
+
|
| 518 |
+
@app.get("/health")
|
| 519 |
+
async def _health():
|
| 520 |
+
return health_check()
|
| 521 |
+
|
| 522 |
+
@app.get("/info")
|
| 523 |
+
async def _info():
|
| 524 |
+
return get_model_info()
|
| 525 |
+
|
| 526 |
+
@app.post("/query")
|
| 527 |
+
async def _query(payload: QueryIn):
|
| 528 |
+
# Boş alanları at, handler.query interface'ine aynen gönder
|
| 529 |
+
return query({k: v for k, v in payload.dict().items() if v is not None})
|
| 530 |
+
|
| 531 |
+
else:
|
| 532 |
+
app = None # uvicorn handler:app çalıştırıldığında import error verir
|