Spaces:
Sleeping
Sleeping
Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,80 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import torch
|
| 2 |
+
from diffusers import FluxPipeline
|
| 3 |
+
import streamlit as st
|
| 4 |
+
|
| 5 |
+
pipe = FluxPipeline.from_pretrained("black-forest-labs/FLUX.1-dev", torch_dtype=torch.bfloat16)
|
| 6 |
+
pipe.enable_model_cpu_offload() # Save VRAM by offloading to CPU (remove if you have enough GPU power)
|
| 7 |
+
|
| 8 |
+
st.set_page_config(page_title="🔥 MemeForge - Text-to-Meme Generator 🔥", page_icon="🔥", layout="wide")
|
| 9 |
+
st.markdown("""
|
| 10 |
+
<style>
|
| 11 |
+
.title {
|
| 12 |
+
font-size: 3em;
|
| 13 |
+
font-weight: bold;
|
| 14 |
+
color: #FF6347;
|
| 15 |
+
text-align: center;
|
| 16 |
+
padding: 20px;
|
| 17 |
+
}
|
| 18 |
+
.description {
|
| 19 |
+
font-size: 1.2em;
|
| 20 |
+
text-align: center;
|
| 21 |
+
color: #666;
|
| 22 |
+
}
|
| 23 |
+
.input-box {
|
| 24 |
+
font-size: 1.5em;
|
| 25 |
+
padding: 10px;
|
| 26 |
+
border-radius: 8px;
|
| 27 |
+
border: 2px solid #FF6347;
|
| 28 |
+
margin: 10px auto;
|
| 29 |
+
display: block;
|
| 30 |
+
width: 60%;
|
| 31 |
+
background-color: #fff3e3;
|
| 32 |
+
}
|
| 33 |
+
.generate-button {
|
| 34 |
+
background-color: #FF6347;
|
| 35 |
+
color: white;
|
| 36 |
+
font-size: 1.2em;
|
| 37 |
+
padding: 10px 30px;
|
| 38 |
+
border: none;
|
| 39 |
+
border-radius: 8px;
|
| 40 |
+
cursor: pointer;
|
| 41 |
+
}
|
| 42 |
+
.generate-button:hover {
|
| 43 |
+
background-color: #FF4500;
|
| 44 |
+
}
|
| 45 |
+
.footer {
|
| 46 |
+
text-align: center;
|
| 47 |
+
font-size: 1.2em;
|
| 48 |
+
color: #888;
|
| 49 |
+
padding: 30px;
|
| 50 |
+
}
|
| 51 |
+
</style>
|
| 52 |
+
""", unsafe_allow_html=True)
|
| 53 |
+
|
| 54 |
+
st.markdown('<div class="title">🔥 MemeForge - Text-to-Meme Generator 🔥</div>', unsafe_allow_html=True)
|
| 55 |
+
st.markdown('<div class="description">Enter a description, and the AI will generate a meme image for you!</div>', unsafe_allow_html=True)
|
| 56 |
+
input_text = st.text_input("Enter meme description:", key="input", placeholder="e.g., A funny dog looking confused.")
|
| 57 |
+
if st.button("Generate Meme", key="generate", help="Click to generate a meme from your description"):
|
| 58 |
+
if input_text:
|
| 59 |
+
modified_prompt = "MEME of an Image of " + input_text
|
| 60 |
+
|
| 61 |
+
image = pipe(
|
| 62 |
+
modified_prompt,
|
| 63 |
+
height=1024,
|
| 64 |
+
width=1024,
|
| 65 |
+
guidance_scale=3.5,
|
| 66 |
+
num_inference_steps=50,
|
| 67 |
+
max_sequence_length=512,
|
| 68 |
+
generator=torch.Generator("cpu").manual_seed(0)
|
| 69 |
+
).images[0]
|
| 70 |
+
|
| 71 |
+
st.image(image, caption="Your Generated Meme", use_column_width=True)
|
| 72 |
+
|
| 73 |
+
# Save the image
|
| 74 |
+
image.save("generated_meme.png")
|
| 75 |
+
else:
|
| 76 |
+
st.warning("Please enter a description to generate a meme.")
|
| 77 |
+
|
| 78 |
+
|
| 79 |
+
|
| 80 |
+
|