Chatbot
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

46 lines
1.1 KiB

import runpod
import subprocess
import requests
import time
def check_api_availability(host):
while True:
try:
response = requests.get(host)
return
except requests.exceptions.RequestException as e:
print(f"API is not available, retrying in 200ms... ({e})")
except Exception as e:
print('something went wrong')
time.sleep(200/1000)
check_api_availability("http://127.0.0.1:3000/sdapi/v1/txt2img")
print('run handler')
def handler(event):
'''
This is the handler function that will be called by the serverless.
'''
print('got event')
print(event)
cmd = 'txt2img'
if 'cmd' in event:
cmd = event["cmd"]
if 'api_endpoint' in event["input"]:
cmd = event["input"]["api_endpoint"]
del event["input"]["api_endpoint"]
response = requests.post(url=f'http://127.0.0.1:3000/sdapi/v1/{cmd}', json=event["input"])
json = response.json()
# do the things
print(json)
# return the output that you want to be returned like pre-signed URLs to output artifacts
return json
runpod.serverless.start({"handler": handler})