File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -4,6 +4,8 @@ ARG COG_VERSION
44
55FROM r8.im/${COG_REPO}/${COG_MODEL}@sha256:${COG_VERSION}
66
7+ ENV RUNPOD_REQUEST_TIMEOUT=600
8+
79# Install necessary packages and Python 3.10
810RUN apt-get update && apt-get upgrade -y && \
911 apt-get install -y --no-install-recommends software-properties-common curl git openssh-server && \
@@ -21,4 +23,4 @@ RUN /opt/venv/bin/pip install runpod
2123
2224ADD src/handler.py /rp_handler.py
2325
24- CMD ["/opt/venv/bin/python3" , "-u" , "/rp_handler.py" ]
26+ CMD ["/opt/venv/bin/python3" , "-u" , "/rp_handler.py" ]
Original file line number Diff line number Diff line change 11import time
22import subprocess
3+ import os
34
45import runpod
56import requests
67from requests .adapters import HTTPAdapter , Retry
78
9+ TIMEOUT = int (os .environ .get ("RUNPOD_REQUEST_TIMEOUT" , "600" ))
10+
811LOCAL_URL = "http://127.0.0.1:5000"
912
1013cog_session = requests .Session ()
@@ -46,13 +49,14 @@ def run_inference(inference_request):
4649 Run inference on a request.
4750 '''
4851 response = cog_session .post (url = f'{ LOCAL_URL } /predictions' ,
49- json = inference_request , timeout = 600 )
52+ json = inference_request , timeout = TIMEOUT )
53+
54+ if response .status_code != 200 :
55+ print ("Request failed - reason :" , response .status_code , response .text )
56+
5057 return response .json ()
5158
5259
53- # ---------------------------------------------------------------------------- #
54- # RunPod Handler #
55- # ---------------------------------------------------------------------------- #
5660def handler (event ):
5761 '''
5862 This is the handler function that will be called by the serverless.
@@ -68,4 +72,4 @@ def handler(event):
6872
6973 print ("Cog API Service is ready. Starting RunPod serverless handler..." )
7074
71- runpod .serverless .start ({"handler" : handler })
75+ runpod .serverless .start ({"handler" : handler })
You can’t perform that action at this time.
0 commit comments