HarshRathi09
commited on
Commit
β’
bc3c070
1
Parent(s):
e4373fc
Delete Image_Generator.py
Browse files- Image_Generator.py +0 -109
Image_Generator.py
DELETED
@@ -1,109 +0,0 @@
|
|
1 |
-
import streamlit as st
|
2 |
-
from diffusers import DiffusionPipeline
|
3 |
-
import torch
|
4 |
-
from PIL import Image
|
5 |
-
# Custom CSS to improve the appearance
|
6 |
-
st.markdown("""
|
7 |
-
<style>
|
8 |
-
.stApp {
|
9 |
-
background-image:linear-gradient(to bottom, #000000 ,#000814 ,#001d3d, #003566);
|
10 |
-
}
|
11 |
-
.main-title {
|
12 |
-
font-size: 3rem !important;
|
13 |
-
color: #f1faee;
|
14 |
-
text-align: center;
|
15 |
-
padding: 1rem 0;
|
16 |
-
}
|
17 |
-
.subtitle {
|
18 |
-
font-size: 1.2rem;
|
19 |
-
color: #f1faee;
|
20 |
-
text-align: center;
|
21 |
-
margin-bottom: 2rem;
|
22 |
-
}
|
23 |
-
.stTextInput > div > div > input {
|
24 |
-
font-size: 1.2rem;
|
25 |
-
}
|
26 |
-
.generate-button {
|
27 |
-
font-size: 1.2rem;
|
28 |
-
border-radius: 10px;
|
29 |
-
padding: 0.5rem 1rem;
|
30 |
-
}
|
31 |
-
.info-section {
|
32 |
-
background-color: #ffffff;
|
33 |
-
padding: 1rem;
|
34 |
-
border-radius: 10px;
|
35 |
-
margin-top: 2rem;
|
36 |
-
}
|
37 |
-
</style>
|
38 |
-
""", unsafe_allow_html=True)
|
39 |
-
|
40 |
-
# Initialize the Stable Diffusion pipeline
|
41 |
-
@st.cache_resource
|
42 |
-
def load_image_model():
|
43 |
-
# Ensure that you are using the correct device (GPU if available)
|
44 |
-
pipe = DiffusionPipeline.from_pretrained("CompVis/stable-diffusion-v1-4")
|
45 |
-
if torch.cuda.is_available():
|
46 |
-
pipe.to("cuda")
|
47 |
-
return pipe
|
48 |
-
|
49 |
-
pipe = load_image_model()
|
50 |
-
|
51 |
-
# Streamlit interface
|
52 |
-
st.markdown("<h1 class='main-title'>πΌοΈ AI Image Generator</h1>", unsafe_allow_html=True)
|
53 |
-
st.markdown("<p class='subtitle'>Describe the image you want to create, and the AI will generate it for you.</p>", unsafe_allow_html=True)
|
54 |
-
|
55 |
-
# Main interaction area
|
56 |
-
image_description = st.text_input("ποΈ Describe the image you want to create",
|
57 |
-
placeholder="E.g., A sunset over a mountain range")
|
58 |
-
|
59 |
-
if st.button("π¨ Generate Image"):
|
60 |
-
if image_description.strip():
|
61 |
-
with st.spinner("π¨ Generating your image..."):
|
62 |
-
st.warning("Image generation may take some time. Please be patient.") # Display warning message
|
63 |
-
try:
|
64 |
-
# Generate the image
|
65 |
-
image = pipe(image_description).images[0]
|
66 |
-
|
67 |
-
# Display the generated image
|
68 |
-
st.image(image, caption="Generated Image", use_column_width=True)
|
69 |
-
|
70 |
-
# Provide download button for the generated image
|
71 |
-
img_path = "generated_image.png"
|
72 |
-
image.save(img_path)
|
73 |
-
|
74 |
-
with open(img_path, "rb") as file:
|
75 |
-
st.download_button(
|
76 |
-
label="π₯ Download Image",
|
77 |
-
data=file,
|
78 |
-
file_name="generated_image.png",
|
79 |
-
mime="image/png"
|
80 |
-
)
|
81 |
-
except Exception as e:
|
82 |
-
st.error(f"π Oops! An error occurred: {str(e)}")
|
83 |
-
else:
|
84 |
-
st.warning("π€ Please enter a description for your image.")
|
85 |
-
|
86 |
-
# Information sections
|
87 |
-
st.markdown("---")
|
88 |
-
|
89 |
-
col1, col2 = st.columns(2)
|
90 |
-
|
91 |
-
with col1:
|
92 |
-
st.markdown("### π How it works")
|
93 |
-
st.markdown("""
|
94 |
-
1. π Describe the image you want
|
95 |
-
2. π±οΈ Click 'Generate Image'
|
96 |
-
3. π¨ View your AI-generated artwork
|
97 |
-
4. π₯ Download and share!
|
98 |
-
""")
|
99 |
-
|
100 |
-
with col2:
|
101 |
-
st.markdown("### π¨ Tips for great results")
|
102 |
-
st.markdown("""
|
103 |
-
- Be specific about objects and settings
|
104 |
-
- Mention style, genre, or mood
|
105 |
-
- Describe the colors and lighting
|
106 |
-
""")
|
107 |
-
|
108 |
-
# Footer
|
109 |
-
st.markdown("---")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|