Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,13 +1,15 @@
|
|
| 1 |
from diffusers import StableDiffusionPipeline
|
| 2 |
import torch
|
| 3 |
import streamlit as st
|
| 4 |
-
from transformers import pipeline
|
| 5 |
|
| 6 |
-
|
| 7 |
-
|
| 8 |
-
|
| 9 |
|
| 10 |
-
|
|
|
|
|
|
|
|
|
|
| 11 |
|
| 12 |
# Custom styling for the page
|
| 13 |
st.markdown("""
|
|
@@ -55,16 +57,19 @@ st.markdown("""
|
|
| 55 |
</style>
|
| 56 |
""", unsafe_allow_html=True)
|
| 57 |
|
|
|
|
| 58 |
st.markdown('<div class="title">π₯ MemeForge - Text-to-Meme Generator π₯</div>', unsafe_allow_html=True)
|
| 59 |
st.markdown('<div class="description">Enter a description, and the AI will generate a meme image for you!</div>', unsafe_allow_html=True)
|
| 60 |
|
|
|
|
| 61 |
input_text = st.text_input("Enter meme description:", key="input", placeholder="e.g., A funny dog looking confused.")
|
| 62 |
|
|
|
|
| 63 |
if st.button("Generate Meme", key="generate", help="Click to generate a meme from your description"):
|
| 64 |
if input_text:
|
| 65 |
modified_prompt = "MEME of an Image of " + input_text
|
| 66 |
|
| 67 |
-
# Generate image
|
| 68 |
image = pipe(modified_prompt, num_inference_steps=10).images[0]
|
| 69 |
|
| 70 |
# Display the generated image
|
|
@@ -74,3 +79,4 @@ if st.button("Generate Meme", key="generate", help="Click to generate a meme fro
|
|
| 74 |
image.save("generated_meme.png")
|
| 75 |
else:
|
| 76 |
st.warning("Please enter a description to generate a meme.")
|
|
|
|
|
|
| 1 |
from diffusers import StableDiffusionPipeline
|
| 2 |
import torch
|
| 3 |
import streamlit as st
|
|
|
|
| 4 |
|
| 5 |
+
# Load the model
|
| 6 |
+
model_id = "CompVis/stable-diffusion-v1-4"
|
| 7 |
+
device = "cuda"
|
| 8 |
|
| 9 |
+
pipe = StableDiffusionPipeline.from_pretrained(model_id, torch_dtype=torch.float16)
|
| 10 |
+
pipe = pipe.to(device)
|
| 11 |
+
|
| 12 |
+
st.set_page_config(page_title="π₯ Memeify - Text-to-Meme Generator π₯", page_icon="π₯", layout="wide")
|
| 13 |
|
| 14 |
# Custom styling for the page
|
| 15 |
st.markdown("""
|
|
|
|
| 57 |
</style>
|
| 58 |
""", unsafe_allow_html=True)
|
| 59 |
|
| 60 |
+
# Title and description
|
| 61 |
st.markdown('<div class="title">π₯ MemeForge - Text-to-Meme Generator π₯</div>', unsafe_allow_html=True)
|
| 62 |
st.markdown('<div class="description">Enter a description, and the AI will generate a meme image for you!</div>', unsafe_allow_html=True)
|
| 63 |
|
| 64 |
+
# User input for meme description
|
| 65 |
input_text = st.text_input("Enter meme description:", key="input", placeholder="e.g., A funny dog looking confused.")
|
| 66 |
|
| 67 |
+
# Generate meme image when button is clicked
|
| 68 |
if st.button("Generate Meme", key="generate", help="Click to generate a meme from your description"):
|
| 69 |
if input_text:
|
| 70 |
modified_prompt = "MEME of an Image of " + input_text
|
| 71 |
|
| 72 |
+
# Generate image from the prompt
|
| 73 |
image = pipe(modified_prompt, num_inference_steps=10).images[0]
|
| 74 |
|
| 75 |
# Display the generated image
|
|
|
|
| 79 |
image.save("generated_meme.png")
|
| 80 |
else:
|
| 81 |
st.warning("Please enter a description to generate a meme.")
|
| 82 |
+
|