-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.py
53 lines (45 loc) · 2.17 KB
/
app.py
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
# Import necessary libraries and modules
import streamlit as st
import openai
from model import generate_images_using_openai, generate_images_using_huggingface_diffusers
# Get API key
OPENAI_API_KEY = st.secrets['OPENAI_API_KEY']
# Set OpenAI API key
openai.api_key = OPENAI_API_KEY
# Set page configuration and title for Streamlit
st.set_page_config(page_title="TextifyImage", page_icon="🔤")
# Streamlit Code
choice = st.sidebar.selectbox("Select your choice", ["Home", "DALL-E", "Huggingface Diffusers"])
if choice == "Home":
# Home page
st.title("🤖 TextifyImage")
with st.expander("About the App"):
st.write("Unleash your imagination with cutting-edge AI. Harnessing the power of OpenAI's DALL-E model and huggingface's Stable diffusion model, effortlessly transform text into stunning visuals that bring your words to life.")
elif choice == "DALL-E":
# DALL-E image generation
st.subheader("Image generation using Open AI's DALL-E")
input_prompt = st.text_input("Enter your text prompt")
if input_prompt is not None:
if st.button("Generate Image"):
image_url = generate_images_using_openai(input_prompt)
st.image(image_url, caption="Generated by DALL-E")
elif choice == "Huggingface Diffusers":
# Huggingface Diffusers image generation
st.subheader("Image generation using Huggingface Diffusers (Takes a lot of time to generate)")
input_prompt = st.text_input("Enter your text prompt")
if input_prompt is not None:
if st.button("Generate Image"):
st.text("This might take a few minutes...")
st.text("Unfortunately, Due to github's file size policy, I couldn't upload Huggingface Diffuser 5gb pretrained weight file :(")
st.text("You can download weights from here:")
st.text("https://huggingface.co/runwayml/stable-diffusion-v1-5/blob/main/v1-5-pruned-emaonly.ckpt")
# Hide Streamlit header, footer, and menu
hide_st_style = """
<style>
#MainMenu {visibility: hidden;}
footer {visibility: hidden;}
header {visibility: hidden;}
</style>
"""
# Apply CSS code to hide header, footer, and menu
st.markdown(hide_st_style, unsafe_allow_html=True)