Spaces:
Runtime error
Runtime error
Pedro Cuenca
commited on
Commit
·
63679e9
1
Parent(s):
7ef7bd9
Move client api to backend.py
Browse files- app/streamlit/app.py +1 -20
- app/streamlit/backend.py +30 -0
app/streamlit/app.py
CHANGED
|
@@ -1,28 +1,9 @@
|
|
| 1 |
#!/usr/bin/env python
|
| 2 |
# coding: utf-8
|
| 3 |
|
| 4 |
-
import base64
|
| 5 |
-
from io import BytesIO
|
| 6 |
-
|
| 7 |
-
import requests
|
| 8 |
import streamlit as st
|
| 9 |
-
from PIL import Image
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
class ServiceError(Exception):
|
| 13 |
-
def __init__(self, status_code):
|
| 14 |
-
self.status_code = status_code
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
def get_images_from_backend(prompt, backend_url):
|
| 18 |
-
r = requests.post(backend_url, json={"prompt": prompt})
|
| 19 |
-
if r.status_code == 200:
|
| 20 |
-
images = r.json()["images"]
|
| 21 |
-
images = [Image.open(BytesIO(base64.b64decode(img))) for img in images]
|
| 22 |
-
return images
|
| 23 |
-
else:
|
| 24 |
-
raise ServiceError(r.status_code)
|
| 25 |
|
|
|
|
| 26 |
|
| 27 |
st.sidebar.markdown(
|
| 28 |
"""
|
|
|
|
| 1 |
#!/usr/bin/env python
|
| 2 |
# coding: utf-8
|
| 3 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 4 |
import streamlit as st
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 5 |
|
| 6 |
+
from backend import ServiceError, get_images_from_backend, get_model_version
|
| 7 |
|
| 8 |
st.sidebar.markdown(
|
| 9 |
"""
|
app/streamlit/backend.py
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Client requests to Dalle-Mini Backend server
|
| 2 |
+
|
| 3 |
+
import requests
|
| 4 |
+
from io import BytesIO
|
| 5 |
+
import base64
|
| 6 |
+
from PIL import Image
|
| 7 |
+
|
| 8 |
+
class ServiceError(Exception):
|
| 9 |
+
def __init__(self, status_code):
|
| 10 |
+
self.status_code = status_code
|
| 11 |
+
|
| 12 |
+
def get_images_from_backend(prompt, backend_url):
|
| 13 |
+
r = requests.post(
|
| 14 |
+
backend_url,
|
| 15 |
+
json={"prompt": prompt}
|
| 16 |
+
)
|
| 17 |
+
if r.status_code == 200:
|
| 18 |
+
images = r.json()["images"]
|
| 19 |
+
images = [Image.open(BytesIO(base64.b64decode(img))) for img in images]
|
| 20 |
+
return images
|
| 21 |
+
else:
|
| 22 |
+
raise ServiceError(r.status_code)
|
| 23 |
+
|
| 24 |
+
def get_model_version(url):
|
| 25 |
+
r = requests.get(url)
|
| 26 |
+
if r.status_code == 200:
|
| 27 |
+
version = r.json()["version"]
|
| 28 |
+
return version
|
| 29 |
+
else:
|
| 30 |
+
raise ServiceError(r.status_code)
|