Spaces:
Runtime error
Runtime error
File size: 863 Bytes
eb60b1e |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
# Client requests to Dalle-Mini Backend server
import base64
from io import BytesIO
import requests
from PIL import Image
class ServiceError(Exception):
def __init__(self, status_code):
self.status_code = status_code
def get_images_from_backend(prompt, backend_url):
r = requests.post(backend_url, json={"prompt": prompt})
if r.status_code == 200:
json = r.json()
images = json["images"]
images = [Image.open(BytesIO(base64.b64decode(img))) for img in images]
version = json.get("version", "unknown")
return {"images": images, "version": version}
else:
raise ServiceError(r.status_code)
def get_model_version(url):
r = requests.get(url)
if r.status_code == 200:
version = r.json()["version"]
return version
else:
raise ServiceError(r.status_code)
|