File size: 3,866 Bytes
fb96795
 
 
4baf6f4
fb96795
4baf6f4
 
 
 
fb96795
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
4baf6f4
fb96795
4baf6f4
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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
import streamlit as st
# import openai
from streamlit_extras.stylable_container import stylable_container
from dotenv import load_dotenv
import replicate
import os
load_dotenv()
REPLICATE_API_TOKEN = os.environ.get("REPLICATE_API_TOKEN")
replicate = replicate.Client(api_token=REPLICATE_API_TOKEN)
streamlit_style = """
            <style>
            #MainMenu {visibility: hidden;}
            footer {visibility: hidden;}
            video{width:200px;}
            .css-1wbqy5l {visibility: hidden;}
            .css-15zrgzn {visibility: hidden;}
            .css-klqnuk {visibility: hidden;}
            .en6cib64 {visibility: hidden;}
            .css-1u4fkce {visibility: hidden;}
            .en6cib62 {visibility: hidden;}
            .css-19rxjzo, .ef3psqc11 {
            background-color: purple;
            text-color: white;
            }
            div.stButton > button:first-child {
            background-color: red;
            text-weight: bold;
            }
            </style>
            """
def page5():
    # st.title("Text to Image")
    with stylable_container(
         key="title",
         css_styles=[
             """ span {
                text-align: center;
                padding-top: 0px;
                padding-right: 0px;
                padding-bottom: 0px;
                padding-left: 0px;
                }"""
                ,
                """
                st-emotion-cache-0{
                     text-align: center;
                padding-top: 0px;
                padding-right: 0px;
                padding-bottom: 0px;
                padding-left: 0px;
                }""",
                
                """
                .e1f1d6gn0{
                     text-align: center;
                padding-top: 0px;
                padding-right: 0px;
                padding-bottom: 0px;
                padding-left: 0px;
                }
        """,
        ],
        
    ):
        st.markdown("<h3>Text to Image<h3>", unsafe_allow_html=True)
        st.markdown(streamlit_style, unsafe_allow_html=True) 

    # st.info("""#### NOTE: you can download image by \
    # right clicking on the image and select save image as option""")
    with st.form(key='form'):
        prompt = st.text_input(label='Enter text prompt for image generation')
        placeholder=st.empty()
        col1,col2=placeholder.columns(2)
        number_of_image = col1.number_input("Number of Images to Generate", step=1, min_value=1, max_value=8, value=1, placeholder="Type a number...")
        # size = st.selectbox('Select size of the images', 
        #                     ('256x256', '512x512', '1024x1024'))
        # num_images = st.selectbox('Enter number of images to be generated', (1,2,3,4))
        
        submit_button = st.form_submit_button(label='Generate Image')
        

    if submit_button:
        if prompt and number_of_image:
            with st.spinner("Generating Image"):
                outputs = replicate.run(
                "stability-ai/stable-diffusion:ac732df83cea7fff18b8472768c88ad041fa750ff7682a21affe81863cbe77e4",
                input={
                "width": 768,
                "height": 448,
                "prompt": prompt,
                "scheduler": "K_EULER",
                "num_outputs": number_of_image,
                "guidance_scale": 7.5,
                "num_inference_steps": 50
                }
                    )
                
                # for output in outputs:
                #     st.image(output,caption=prompt)
                placeholder=st.empty()
                col1,col2=placeholder.columns(2)
                for index, output in enumerate(outputs):
                    if index%2==0:
                        col1.image(output,caption=prompt)
                    else:
                        col2.image(output,caption=prompt)