Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,61 +1,61 @@
|
|
| 1 |
-
import streamlit as st
|
| 2 |
-
from app_logic import text2image
|
| 3 |
-
|
| 4 |
-
|
| 5 |
-
from io import BytesIO
|
| 6 |
-
|
| 7 |
-
|
| 8 |
-
def app():
|
| 9 |
-
st.header("Text-to-image Web App")
|
| 10 |
-
st.subheader("Powered by Hugging Face")
|
| 11 |
-
user_input = st.text_area(
|
| 12 |
-
"Enter your text prompt below and click the button to submit."
|
| 13 |
-
)
|
| 14 |
-
|
| 15 |
-
option = st.selectbox(
|
| 16 |
-
"Select model
|
| 17 |
-
(
|
| 18 |
-
"
|
| 19 |
-
"
|
| 20 |
-
"
|
| 21 |
-
"
|
| 22 |
-
"
|
| 23 |
-
"
|
| 24 |
-
"
|
| 25 |
-
"SG161222/RealVisXL_V3.0",
|
| 26 |
-
"
|
| 27 |
-
),
|
| 28 |
-
)
|
| 29 |
-
|
| 30 |
-
with st.form("my_form"):
|
| 31 |
-
submit = st.form_submit_button(label="Submit text prompt")
|
| 32 |
-
|
| 33 |
-
if submit:
|
| 34 |
-
with st.spinner(text="Generating image ... It may take
|
| 35 |
-
im, start, end = text2image(prompt=user_input, repo_id=option)
|
| 36 |
-
|
| 37 |
-
buf = BytesIO()
|
| 38 |
-
im.save(buf, format="PNG")
|
| 39 |
-
byte_im = buf.getvalue()
|
| 40 |
-
|
| 41 |
-
hours, rem = divmod(end - start, 3600)
|
| 42 |
-
minutes, seconds = divmod(rem, 60)
|
| 43 |
-
|
| 44 |
-
st.success(
|
| 45 |
-
"Processing time: {:0>2}:{:0>2}:{:05.2f}.".format(
|
| 46 |
-
int(hours), int(minutes), seconds
|
| 47 |
-
)
|
| 48 |
-
)
|
| 49 |
-
|
| 50 |
-
st.image(im)
|
| 51 |
-
|
| 52 |
-
st.download_button(
|
| 53 |
-
label="Click here to download",
|
| 54 |
-
data=byte_im,
|
| 55 |
-
file_name="generated_image.png",
|
| 56 |
-
mime="image/png",
|
| 57 |
-
)
|
| 58 |
-
|
| 59 |
-
|
| 60 |
-
if __name__ == "__main__":
|
| 61 |
app()
|
|
|
|
| 1 |
+
import streamlit as st
|
| 2 |
+
from app_logic import text2image
|
| 3 |
+
|
| 4 |
+
|
| 5 |
+
from io import BytesIO
|
| 6 |
+
|
| 7 |
+
|
| 8 |
+
def app():
|
| 9 |
+
st.header("Text-to-image Web App")
|
| 10 |
+
st.subheader("Powered by Hugging Face")
|
| 11 |
+
user_input = st.text_area(
|
| 12 |
+
"Enter your text prompt below and click the button to submit."
|
| 13 |
+
)
|
| 14 |
+
|
| 15 |
+
option = st.selectbox(
|
| 16 |
+
"Select model ",
|
| 17 |
+
(
|
| 18 |
+
"black-forest-labs/FLUX.1-dev",
|
| 19 |
+
"stabilityai/stable-diffusion-2-1",
|
| 20 |
+
"runwayml/stable-diffusion-v1-5",
|
| 21 |
+
"CompVis/stable-diffusion-v1-4",
|
| 22 |
+
"prithivMLmods/Canopus-Realism-LoRA",
|
| 23 |
+
"SG161222/RealVisXL_V4.0_Lightning",
|
| 24 |
+
"prompthero/openjourney",
|
| 25 |
+
"SG161222/RealVisXL_V3.0",
|
| 26 |
+
"mukaist/DALLE-4K",
|
| 27 |
+
),
|
| 28 |
+
)
|
| 29 |
+
|
| 30 |
+
with st.form("my_form"):
|
| 31 |
+
submit = st.form_submit_button(label="Submit text prompt")
|
| 32 |
+
|
| 33 |
+
if submit:
|
| 34 |
+
with st.spinner(text="Generating image ... It may take some time. Please wait ... ."):
|
| 35 |
+
im, start, end = text2image(prompt=user_input, repo_id=option)
|
| 36 |
+
|
| 37 |
+
buf = BytesIO()
|
| 38 |
+
im.save(buf, format="PNG")
|
| 39 |
+
byte_im = buf.getvalue()
|
| 40 |
+
|
| 41 |
+
hours, rem = divmod(end - start, 3600)
|
| 42 |
+
minutes, seconds = divmod(rem, 60)
|
| 43 |
+
|
| 44 |
+
st.success(
|
| 45 |
+
"Processing time: {:0>2}:{:0>2}:{:05.2f}.".format(
|
| 46 |
+
int(hours), int(minutes), seconds
|
| 47 |
+
)
|
| 48 |
+
)
|
| 49 |
+
|
| 50 |
+
st.image(im)
|
| 51 |
+
|
| 52 |
+
st.download_button(
|
| 53 |
+
label="Click here to download",
|
| 54 |
+
data=byte_im,
|
| 55 |
+
file_name="generated_image.png",
|
| 56 |
+
mime="image/png",
|
| 57 |
+
)
|
| 58 |
+
|
| 59 |
+
|
| 60 |
+
if __name__ == "__main__":
|
| 61 |
app()
|