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 = """
"""
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("
Text to Image", 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)