try handle
Browse files462 unmodified lines46346446546646746846947047147247347447547629 unmodified lines506507508509510511512513514515516517518462 unmodified linesprint(f"Failed to initialize model: {e}")return False# Initialize model on importmodel_initialized = initialize_model()# Main endpoint function for Hugging Facedef query(payload):"""Main endpoint function for Hugging Face inference API"""if not model_initialized:return {"error": "Model not initialized"}try:# Extract parameters from payload29 unmodified lines"cuda_available": torch.cuda.is_available(),"llava_available": LLAVA_AVAILABLE,"transformers_available": TRANSFORMERS_AVAILABLE,"cv2_available": CV2_AVAILABLE}def get_model_info():"""Get model information"""if not model_initialized:return {"error": "Model not initialized"}return {"model_path": args.model_path if args else "Unknown",462 unmodified lines46346446546646746846947047147247347447547647747847948048148229 unmodified lines512513514515516517518519520521522523524525526527528529462 unmodified linesprint(f"Failed to initialize model: {e}")return False# Don't initialize model on import - do it lazilymodel_initialized = False# Main endpoint function for Hugging Facedef query(payload):"""Main endpoint function for Hugging Face inference API"""global model_initialized# Lazy initialization - initialize model on first callif not model_initialized:print("Initializing model on first query...")model_initialized = initialize_model()if not model_initialized:return {"error": "Model initialization failed"}try:# Extract parameters from payload29 unmodified lines"cuda_available": torch.cuda.is_available(),"llava_available": LLAVA_AVAILABLE,"transformers_available": TRANSFORMERS_AVAILABLE,"cv2_available": CV2_AVAILABLE,"lazy_loading": True # Model will be loaded on first query}def get_model_info():"""Get model information"""if not model_initialized:return {"error": "Model not initialized yet","lazy_loading": True,"note": "Model will be loaded on first query"}return {"model_path": args.model_path if args else "Unknown",
handler.py+16-5