Spaces:
Sleeping
Sleeping
File size: 10,982 Bytes
fe9854b |
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 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 |
import streamlit as st
from streamlit_js_eval import streamlit_js_eval
from PIL import Image
import io
import mongo_db
# Functions for image and prompt generation
from image_model import (
flux,
stable_diffusion,
)
from prompt_model import Qwen_72b, microsoft_phi, Mixtral
# Set page config with a custom title and layout
st.set_page_config(
page_title="Welcome to ImagiGen: AI-Powered Image Generation for Automated Fashion Design",
layout="wide",
initial_sidebar_state="expanded",
)
# Custom CSS for fonts, background, and animations
st.markdown(
"""
<style>
/* Add a custom font */
@import url('https://fonts.googleapis.com/css2?family=Poppins:wght@300;400;600&display=swap');
body {
font-family: 'Poppins', sans-serif;
background: linear-gradient(135deg, #f8f9fa, #e9ecef);
animation: gradient-animation 10s ease infinite;
}
/* Header and title styles */
h1, h2, h3 {
color: #343a40;
text-align: center;
}
/* Button styles */
.stButton button {
background-color: #007bff;
color: white;
border-radius: 8px;
transition: all 0.3s ease;
}
.stButton button:hover {
background-color: #0056b3;
transform: scale(1.05);
}
/* Smooth gradient animation */
@keyframes gradient-animation {
0% { background: linear-gradient(135deg, #f8f9fa, #e9ecef); }
50% { background: linear-gradient(135deg, #e9ecef, #f8f9fa); }
100% { background: linear-gradient(135deg, #f8f9fa, #e9ecef); }
}
/* Custom input box styling */
input, textarea {
border: 2px solid #ced4da;
border-radius: 5px;
padding: 10px;
}
/* Sidebar customization */
.sidebar .sidebar-content {
background-color: #ffffff;
border-radius: 10px;
padding: 20px;
}
</style>
""",
unsafe_allow_html=True,
)
# List of functions
image_functions = [flux, stable_diffusion]
prompt_functions = [Qwen_72b, microsoft_phi, Mixtral]
# Initialize session state for login status
if "logged_in" not in st.session_state:
st.session_state.logged_in = False
def register():
col1, col2, col3 = st.columns([1, 2, 1]) # Left, Center (main content), Right
with col2:
with st.expander("Register New Account", expanded=False):
st.subheader("Create a New Account", divider="rainbow")
new_email_id = st.text_input("email_id", placeholder="Enter an Email ID")
new_password = st.text_input(
"New Password", type="password", placeholder="Choose a password"
)
confirm_password = st.text_input(
"Confirm Password",
type="password",
placeholder="Re-enter your password",
)
if st.button("Register"):
if new_password != confirm_password:
st.error("Passwords do not match. Please try again.")
elif not new_email_id or not new_password:
st.error("All fields are required.")
else:
response = mongo_db.register(new_email_id, new_password)
print(response)
if "Invalid Email Id" == response :
st.error(
"Invalid Email Id. Please check and try again."
)
elif "Email ID already Registered" == response:
st.error(
"Email ID already Registered. Please choose a different email id."
)
elif "Registration successful" == response:
st.success("Registration successful! You can now log in.")
st.balloons()
else:
st.error("Unexpected error occur. Please Retry....")
# Function to handle login
def login():
col1, col2, col3 = st.columns([1, 2, 1]) # Left, Center (main content), Right
with col2:
_, centre, _ = st.columns([1, 2, 1])
with centre:
st.image("ImagiGen--Logo.svg", use_container_width=True)
st.header("Login Page", divider="rainbow")
st.subheader("Please Login to Continue")
email_id = st.text_input("Email Id", placeholder="Enter your Email Id")
password = st.text_input(
"Password", type="password", placeholder="Enter your password"
)
if st.button("Login"):
response = mongo_db.login(email_id, password)
if response == "Login successful":
st.session_state.logged_in = True
st.success("Login successful! Redirecting...")
st.rerun()
else:
st.error("Invalid email id or password")
# Function for the platform/dashboard page
def platform_page():
_, centre, _ = st.columns([3, 4, 3])
with centre:
st.image("ImagiGen--Logo.svg", use_container_width=True)
st.header("Welcome to ImagiGen: AI-Powered Image Generation for Automated Fashion Design", divider="rainbow")
if st.button("Logout"):
st.session_state.logged_in = False
st.rerun()
st.markdown("### Describe Your Creative Vision")
# Initialize session state for prompts
if "model_1" not in st.session_state:
st.session_state.model_1 = ""
if "model_2" not in st.session_state:
st.session_state.model_2 = ""
if "model_3" not in st.session_state:
st.session_state.model_3 = ""
# User input for the prompt
user_input = st.text_input(
"Enter your description for prompt generation:",
"",
placeholder="E.g., A vivid image of a flowing red silk dress in a windy desert...",
)
if st.button("Generate Prompt"):
with st.spinner("Generating Prompts..."):
st.session_state.model_1 = Qwen_72b(user_input)
st.session_state.model_2 = microsoft_phi(user_input)
st.session_state.model_3 = Mixtral(user_input)
# Display text areas to edit each generated prompt
cols = st.columns(3)
with cols[0]:
st.session_state.model_1 = st.text_area(
"Customize Prompt 1 :", st.session_state.model_1, height=200
)
with cols[1]:
st.session_state.model_2 = st.text_area(
"Customize Prompt 2:", st.session_state.model_2, height=200
)
with cols[2]:
st.session_state.model_3 = st.text_area(
"Customize Prompt 3:", st.session_state.model_3, height=200
)
if st.button("Generate Images"):
prompts = [
st.session_state.model_1,
st.session_state.model_2,
st.session_state.model_3,
]
cols = st.columns(3)
with cols[0]:
with st.spinner(f"Generating Image {1}..."):
try:
image_bytes = image_functions[0](prompts[0])
image = Image.open(io.BytesIO(image_bytes))
st.image(
image,
caption=f"Prompt {1}, Model {1}",
use_container_width=True,
)
except:
st.image(
"error.jpg",
caption="Server error occur",
)
with cols[1]:
with st.spinner(f"Generating Image {2}..."):
try:
image_bytes = image_functions[0](prompts[1])
image = Image.open(io.BytesIO(image_bytes))
st.image(
image,
caption=f"Prompt {2}, Model {1}",
use_container_width=True,
)
except:
st.image(
"error.jpg",
caption="Server error occur",
)
with cols[2]:
with st.spinner(f"Generating Image {3}..."):
try:
image_bytes = image_functions[0](prompts[2])
image = Image.open(io.BytesIO(image_bytes))
st.image(
image,
caption=f"Prompt {3}, Model {1}",
use_container_width=True,
)
except:
st.image(
"error.jpg",
caption="Server error occur",
)
with cols[0]:
with st.spinner(f"Generating Image {4}..."):
try:
image_bytes = image_functions[1](prompts[0])
image = Image.open(io.BytesIO(image_bytes))
st.image(
image,
caption=f"Prompt {1}, Model {2}",
use_container_width=True,
)
except:
st.image(
"error.jpg",
caption="Server error occur",
)
with cols[1]:
with st.spinner(f"Generating Image {5}..."):
try:
image_bytes = image_functions[1](prompts[1])
image = Image.open(io.BytesIO(image_bytes))
st.image(
image,
caption=f"Prompt {2}, Model {2}",
use_container_width=True,
)
except:
st.image(
"error.jpg",
caption="Server error occur",
)
with cols[2]:
with st.spinner(f"Generating Image {6}..."):
try:
image_bytes = image_functions[1](prompts[2])
image = Image.open(io.BytesIO(image_bytes))
st.image(
image,
caption=f"Prompt {3}, Model {2}",
use_container_width=True,
)
except:
st.image(
"error.jpg",
caption="Server error occur",
)
if st.button("Clear/Regenerate"):
st.session_state.model_1 = ""
st.session_state.model_2 = ""
st.session_state.model_3 = ""
st.rerun()
# Main logic to control which page to display
if st.session_state.logged_in:
platform_page()
else:
login()
register()
|