Update handler.py
Browse files359 unmodified lines36036136236336436530 unmodified lines396397398399400401402403404405406407408409359 unmodified linesdef query(payload: dict):"""HF Endpoint entry (demo-like)."""global model_initialized, tokenizer, model, image_processor, context_len, argsif not model_initialized:if not initialize_model():return {"error": "Model initialization failed"}30 unmodified linesreturn {"error": f"Query failed: {e}"}def health_check():return {"status": "healthy","model_initialized": model_initialized,"cuda_available": torch.cuda.is_available(),"llava_available": LLAVA_AVAILABLE,"transformers_available": TRANSFORMERS_AVAILABLE,}def get_model_info():if not model_initialized:return {"error": "Model not initialized"}359 unmodified lines36036136236336436536636736836937030 unmodified lines401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438359 unmodified linesdef query(payload: dict):"""HF Endpoint entry (demo-like)."""global model_initialized, tokenizer, model, image_processor, context_len, args# 🟢 Health check kısayolu: hem {"health_check": true} hem de {"message": "health_check"} desteklenirif payload.get("health_check") or payload.get("message") == "health_check":return health_check()if not model_initialized:if not initialize_model():return {"error": "Model initialization failed"}30 unmodified linesreturn {"error": f"Query failed: {e}"}def health_check():info = {"status": "healthy","model_initialized": model_initialized,"llava_available": LLAVA_AVAILABLE,"transformers_available": TRANSFORMERS_AVAILABLE,"cuda_available": torch.cuda.is_available(),}if torch.cuda.is_available():try:device_index = torch.cuda.current_device()props = torch.cuda.get_device_properties(device_index)total_vram_gb = round(props.total_memory / (1024 ** 3), 2)used_vram_gb = round(torch.cuda.memory_allocated(device_index) / (1024 ** 3), 2)reserved_vram_gb = round(torch.cuda.memory_reserved(device_index) / (1024 ** 3), 2)info.update({"cuda_device_index": device_index,"cuda_name": props.name,"cuda_compute_capability": f"{props.major}.{props.minor}","cuda_total_vram_gb": total_vram_gb,"cuda_used_vram_gb": used_vram_gb,"cuda_reserved_vram_gb": reserved_vram_gb,"torch_version": torch.__version__,"cuda_runtime_version": torch.version.cuda,})except Exception as e:info["cuda_error"] = str(e)return infodef get_model_info():if not model_initialized:return {"error": "Model not initialized"}
handler.py+31-2