Spaces:
Running
Running
maialumiaho
commited on
Commit
•
f86b2f2
1
Parent(s):
ec797ab
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,31 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import streamlit as st
|
2 |
+
import requests
|
3 |
+
import io
|
4 |
+
from PIL import Image
|
5 |
+
import os
|
6 |
+
|
7 |
+
hf_token = os.environ.get("spaces_prototype")
|
8 |
+
API_URL_SD = "https://api-inference.huggingface.co/models/xinsir/controlnet-union-sdxl-1.0"
|
9 |
+
|
10 |
+
def query(payload):
|
11 |
+
response = requests.post(API_URL, headers=headers, json=payload)
|
12 |
+
return response.content
|
13 |
+
|
14 |
+
st.title("text to image model")
|
15 |
+
st.write("Enter a prompt")
|
16 |
+
model = st.selectbox(
|
17 |
+
"choose model",
|
18 |
+
("stable diffusion")
|
19 |
+
|
20 |
+
)
|
21 |
+
prompt = st.text_input("Enter prompt")
|
22 |
+
|
23 |
+
if prompt:
|
24 |
+
if model == "stable diffusion":
|
25 |
+
API_URL = API_URL_SD
|
26 |
+
image_bytes = query({
|
27 |
+
"inputs": prompt,
|
28 |
+
})
|
29 |
+
st.image(image_bytes, caption="Generated image")
|
30 |
+
st.info("Image generated successfully")
|
31 |
+
|