Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import streamlit as st
|
| 2 |
+
from diffusers import StableDiffusionPipeline
|
| 3 |
+
import torch
|
| 4 |
+
from PIL import Image
|
| 5 |
+
|
| 6 |
+
# Load model (run once, slow on CPU)
|
| 7 |
+
@st.cache_resource
|
| 8 |
+
def load_model():
|
| 9 |
+
model_id = "runwayml/stable-diffusion-v1-5" # You can change to your own fine-tuned model
|
| 10 |
+
pipe = StableDiffusionPipeline.from_pretrained(
|
| 11 |
+
model_id,
|
| 12 |
+
torch_dtype=torch.float16 if torch.cuda.is_available() else torch.float32
|
| 13 |
+
)
|
| 14 |
+
pipe = pipe.to("cuda" if torch.cuda.is_available() else "cpu")
|
| 15 |
+
return pipe
|
| 16 |
+
|
| 17 |
+
st.title("🖼️ AI Thumbnail Generator (Stable Diffusion)")
|
| 18 |
+
|
| 19 |
+
# Load Stable Diffusion pipeline
|
| 20 |
+
pipe = load_model()
|
| 21 |
+
|
| 22 |
+
# UI
|
| 23 |
+
prompt = st.text_input("📌 Enter Thumbnail Prompt", value="Minecraft NOOB vs PRO with fire background, bold text")
|
| 24 |
+
|
| 25 |
+
if st.button("Generate Thumbnail"):
|
| 26 |
+
with st.spinner("Generating image..."):
|
| 27 |
+
image = pipe(prompt, guidance_scale=8.5).images[0]
|
| 28 |
+
st.image(image, caption="Generated Thumbnail", use_column_width=True)
|
| 29 |
+
|
| 30 |
+
# Option to download
|
| 31 |
+
img_bytes = image.save("thumbnail.jpg")
|
| 32 |
+
with open("thumbnail.jpg", "rb") as f:
|
| 33 |
+
st.download_button("📥 Download Thumbnail", f, "thumbnail.jpg", "image/jpeg")
|