Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -2,64 +2,18 @@ from diffusers import StableDiffusionPipeline
|
|
2 |
import torch
|
3 |
import streamlit as st
|
4 |
|
5 |
-
# Function to load the model and cache it for better performance
|
6 |
-
@st.cache_resource
|
7 |
-
def load_model():
|
8 |
-
model_id = "CompVis/stable-diffusion-v1-4"
|
9 |
-
device = "cuda" if torch.cuda.is_available() else "cpu" # Check for GPU, otherwise use CPU
|
10 |
-
pipe = StableDiffusionPipeline.from_pretrained(model_id, torch_dtype=torch.float16)
|
11 |
-
pipe = pipe.to(device)
|
12 |
-
return pipe
|
13 |
|
14 |
-
# Load model
|
15 |
-
|
|
|
16 |
|
17 |
-
|
18 |
-
|
|
|
|
|
19 |
|
20 |
# Custom styling for the page
|
21 |
st.markdown("""
|
22 |
-
<style>
|
23 |
-
.title {
|
24 |
-
font-size: 3em;
|
25 |
-
font-weight: bold;
|
26 |
-
color: #FF6347;
|
27 |
-
text-align: center;
|
28 |
-
padding: 20px;
|
29 |
-
}
|
30 |
-
.description {
|
31 |
-
font-size: 1.2em;
|
32 |
-
text-align: center;
|
33 |
-
color: #666;
|
34 |
-
}
|
35 |
-
.input-box {
|
36 |
-
font-size: 1.5em;
|
37 |
-
padding: 10px;
|
38 |
-
border-radius: 8px;
|
39 |
-
border: 2px solid #FF6347;
|
40 |
-
margin: 10px auto;
|
41 |
-
display: block;
|
42 |
-
width: 60%;
|
43 |
-
background-color: #fff3e3;
|
44 |
-
}
|
45 |
-
.generate-button {
|
46 |
-
background-color: #FF6347;
|
47 |
-
color: white;
|
48 |
-
font-size: 1.2em;
|
49 |
-
padding: 10px 30px;
|
50 |
-
border: none;
|
51 |
-
border-radius: 8px;
|
52 |
-
cursor: pointer;
|
53 |
-
}
|
54 |
-
.generate-button:hover {
|
55 |
-
background-color: #FF4500;
|
56 |
-
}
|
57 |
-
.footer {
|
58 |
-
text-align: center;
|
59 |
-
font-size: 1.2em;
|
60 |
-
color: #888;
|
61 |
-
padding: 30px;
|
62 |
-
}
|
63 |
</style>
|
64 |
""", unsafe_allow_html=True)
|
65 |
|
@@ -67,26 +21,24 @@ st.markdown("""
|
|
67 |
st.markdown('<div class="title">π₯ MemeForge - Text-to-Meme Generator π₯</div>', unsafe_allow_html=True)
|
68 |
st.markdown('<div class="description">Enter a description, and the AI will generate a meme image for you!</div>', unsafe_allow_html=True)
|
69 |
|
70 |
-
#
|
71 |
input_text = st.text_input("Enter meme description:", key="input", placeholder="e.g., A funny dog looking confused.")
|
72 |
|
73 |
-
#
|
74 |
if st.button("Generate Meme", key="generate", help="Click to generate a meme from your description"):
|
75 |
if input_text:
|
76 |
-
# Modify prompt for meme generation
|
77 |
modified_prompt = "MEME of an Image of " + input_text
|
78 |
|
79 |
-
#
|
80 |
-
|
81 |
-
|
82 |
-
|
83 |
-
image = image.resize((512, 512))
|
84 |
|
85 |
-
|
86 |
-
|
87 |
|
88 |
-
|
89 |
-
|
90 |
else:
|
91 |
st.warning("Please enter a description to generate a meme.")
|
92 |
|
|
|
2 |
import torch
|
3 |
import streamlit as st
|
4 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
5 |
|
6 |
+
# Load the model
|
7 |
+
model_id = "CompVis/stable-diffusion-v1-4"
|
8 |
+
device = "cuda"
|
9 |
|
10 |
+
pipe = StableDiffusionPipeline.from_pretrained(model_id, torch_dtype=torch.float16)
|
11 |
+
pipe = pipe.to(device)
|
12 |
+
|
13 |
+
st.set_page_config(page_title="π₯ Memeify - Text-to-Meme Generator π₯", page_icon="π₯", layout="wide")
|
14 |
|
15 |
# Custom styling for the page
|
16 |
st.markdown("""
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
17 |
</style>
|
18 |
""", unsafe_allow_html=True)
|
19 |
|
|
|
21 |
st.markdown('<div class="title">π₯ MemeForge - Text-to-Meme Generator π₯</div>', unsafe_allow_html=True)
|
22 |
st.markdown('<div class="description">Enter a description, and the AI will generate a meme image for you!</div>', unsafe_allow_html=True)
|
23 |
|
24 |
+
# User input for meme description
|
25 |
input_text = st.text_input("Enter meme description:", key="input", placeholder="e.g., A funny dog looking confused.")
|
26 |
|
27 |
+
# Generate meme image when button is clicked
|
28 |
if st.button("Generate Meme", key="generate", help="Click to generate a meme from your description"):
|
29 |
if input_text:
|
|
|
30 |
modified_prompt = "MEME of an Image of " + input_text
|
31 |
|
32 |
+
# Show a loading spinner while the image is being generated
|
33 |
+
with st.spinner('Generating your meme...'):
|
34 |
+
# Generate image from the prompt
|
35 |
+
image = pipe(modified_prompt, num_inference_steps=10).images[0]
|
|
|
36 |
|
37 |
+
# Display the generated image
|
38 |
+
st.image(image, caption="Your Generated Meme", use_column_width=True)
|
39 |
|
40 |
+
# Save the image
|
41 |
+
image.save("generated_meme.png")
|
42 |
else:
|
43 |
st.warning("Please enter a description to generate a meme.")
|
44 |
|