File size: 1,657 Bytes
0fd2d93
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
0e1fe38
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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
import streamlit as st
from app_logic import text2image


from io import BytesIO


def app():
    st.header("Text-to-image Web App")
    st.subheader("Powered by Hugging Face")
    user_input = st.text_area(
        "Enter your text prompt below and click the button to submit."
    )

    option = st.selectbox(
        "Select model ",
        (
        "black-forest-labs/FLUX.1-dev",
        "stabilityai/stable-diffusion-2-1",
        "runwayml/stable-diffusion-v1-5",
        "CompVis/stable-diffusion-v1-4",
        "prithivMLmods/Canopus-Realism-LoRA",
        "SG161222/RealVisXL_V4.0_Lightning",
        "prompthero/openjourney",
        "SG161222/RealVisXL_V3.0",
        "mukaist/DALLE-4K",
        ),
    )

    with st.form("my_form"):
        submit = st.form_submit_button(label="Submit text prompt")

    if submit:
        with st.spinner(text="Generating image ... It may take some time. Please wait ... ."):
            im, start, end = text2image(prompt=user_input, repo_id=option)

            buf = BytesIO()
            im.save(buf, format="PNG")
            byte_im = buf.getvalue()

            hours, rem = divmod(end - start, 3600)
            minutes, seconds = divmod(rem, 60)

            st.success(
                "Processing time: {:0>2}:{:0>2}:{:05.2f}.".format(
                    int(hours), int(minutes), seconds
                )
            )

            st.image(im)

            st.download_button(
                label="Click here to download",
                data=byte_im,
                file_name="generated_image.png",
                mime="image/png",
            )


if __name__ == "__main__":
    app()