Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -1,43 +1,25 @@
|
|
1 |
-
from diffusers import StableDiffusionPipeline
|
2 |
import torch
|
3 |
import streamlit as st
|
|
|
4 |
|
5 |
-
#
|
6 |
-
|
7 |
-
|
8 |
-
# Load the model
|
9 |
-
model_id = "CompVis/stable-diffusion-v1-4"
|
10 |
-
device = "cuda"
|
11 |
-
|
12 |
-
pipe = StableDiffusionPipeline.from_pretrained(model_id, torch_dtype=torch.float16)
|
13 |
-
pipe = pipe.to(device)
|
14 |
-
|
15 |
-
# Custom styling for the page
|
16 |
-
st.markdown("""
|
17 |
-
</style>
|
18 |
-
""", unsafe_allow_html=True)
|
19 |
|
20 |
# Title and description
|
21 |
-
st.markdown('<div class="title">π₯
|
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.,
|
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 |
-
|
33 |
-
|
34 |
-
|
35 |
-
|
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.")
|
|
|
|
|
1 |
import torch
|
2 |
import streamlit as st
|
3 |
+
from diffusers import DiffusionPipeline
|
4 |
|
5 |
+
# Load the pre-trained Stable Diffusion model
|
6 |
+
pipe = DiffusionPipeline.from_pretrained("CompVis/stable-diffusion-v1-4")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
7 |
|
8 |
# Title and description
|
9 |
+
st.markdown('<div class="title">π₯ Memeify - Text-to-Meme Generator π₯</div>', unsafe_allow_html=True)
|
10 |
st.markdown('<div class="description">Enter a description, and the AI will generate a meme image for you!</div>', unsafe_allow_html=True)
|
11 |
|
12 |
# User input for meme description
|
13 |
+
input_text = st.text_input("Enter meme description:", key="input", placeholder="e.g., dog dancing")
|
14 |
|
15 |
# Generate meme image when button is clicked
|
16 |
if st.button("Generate Meme", key="generate", help="Click to generate a meme from your description"):
|
17 |
if input_text:
|
18 |
modified_prompt = "MEME of an Image of " + input_text
|
19 |
+
# Generate the image from the modified prompt
|
20 |
+
image = pipe(modified_prompt).images[0]
|
21 |
+
|
22 |
+
# Display the generated image in the Streamlit app
|
23 |
+
st.image(image, caption=f"Meme: {input_text}", use_column_width=True)
|
|
|
|
|
|
|
|
|
|
|
|
|
24 |
else:
|
25 |
+
st.warning("Please enter a description to generate a meme.")
|