Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -2,18 +2,33 @@ import streamlit as st
|
|
2 |
from freeGPT import Client
|
3 |
from PIL import Image
|
4 |
from io import BytesIO
|
|
|
5 |
|
6 |
st.sidebar.title("Stable Diffusion SDXL-Turbo", help="Made with API")
|
7 |
st.sidebar.subheader("By KVI Kontent")
|
8 |
st.sidebar.write("Choose model and enter prompt")
|
|
|
|
|
|
|
9 |
|
10 |
-
model = st.sidebar.selectbox("Choose Model", ("prodia", "pollinations"))
|
11 |
|
12 |
prompt = st.sidebar.text_input("Prompt", "")
|
13 |
|
14 |
-
|
15 |
-
|
16 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
17 |
st.image(image, caption="Generated Image")
|
18 |
-
except Exception as e:
|
19 |
-
st.error(str(e))
|
|
|
2 |
from freeGPT import Client
|
3 |
from PIL import Image
|
4 |
from io import BytesIO
|
5 |
+
import os
|
6 |
|
7 |
st.sidebar.title("Stable Diffusion SDXL-Turbo", help="Made with API")
|
8 |
st.sidebar.subheader("By KVI Kontent")
|
9 |
st.sidebar.write("Choose model and enter prompt")
|
10 |
+
api_key = os.environ['api_key']
|
11 |
+
API_URL_DALLE = "https://api-inference.huggingface.co/models/openskyml/dalle-3-xl"
|
12 |
+
headers = {"Authorization": api_key}
|
13 |
|
14 |
+
model = st.sidebar.selectbox("Choose Model", ("prodia", "pollinations", "Dall-e 3"))
|
15 |
|
16 |
prompt = st.sidebar.text_input("Prompt", "")
|
17 |
|
18 |
+
def Dalle_query(payload):
|
19 |
+
response = requests.post(API_URL_DALLE, headers=headers, json=payload)
|
20 |
+
return response.content
|
21 |
+
|
22 |
+
if model == "prodia" or model == "pollinations":
|
23 |
+
try:
|
24 |
+
resp = Client.create_generation(model, prompt)
|
25 |
+
image = Image.open(BytesIO(resp))
|
26 |
+
st.image(image, caption="Generated Image")
|
27 |
+
except Exception as e:
|
28 |
+
st.error(str(e))
|
29 |
+
elif model == "Dall-e 3":
|
30 |
+
image_bytes = Dalle_query({
|
31 |
+
"inputs": prompt
|
32 |
+
})
|
33 |
+
image = Image.open(BytesIO(image_bytes))
|
34 |
st.image(image, caption="Generated Image")
|
|
|
|