Update app.py
Browse files
app.py
CHANGED
|
@@ -2,8 +2,9 @@ import streamlit as st
|
|
| 2 |
from diffusers import StableDiffusionPipeline
|
| 3 |
import torch
|
| 4 |
from PIL import Image
|
|
|
|
| 5 |
|
| 6 |
-
# Load model
|
| 7 |
@st.cache_resource
|
| 8 |
def load_model():
|
| 9 |
model_id = "runwayml/stable-diffusion-v1-5"
|
|
@@ -15,30 +16,21 @@ def load_model():
|
|
| 15 |
pipe = pipe.to("cuda" if torch.cuda.is_available() else "cpu")
|
| 16 |
return pipe
|
| 17 |
|
| 18 |
-
#
|
| 19 |
-
st.set_page_config(page_title="
|
| 20 |
-
st.title("πΌοΈ AI Thumbnail Generator
|
| 21 |
|
| 22 |
-
# Load model
|
| 23 |
pipe = load_model()
|
| 24 |
|
| 25 |
-
|
| 26 |
-
prompt = st.text_input("π Enter Thumbnail Prompt:", value="Minecraft NOOB vs PRO | fire background | bold text")
|
| 27 |
|
| 28 |
-
|
| 29 |
-
|
| 30 |
-
|
| 31 |
-
|
| 32 |
-
image = result.images[0]
|
| 33 |
-
st.image(image, caption="π Your AI Thumbnail", use_column_width=True)
|
| 34 |
|
| 35 |
-
# Download
|
| 36 |
-
|
| 37 |
-
|
| 38 |
-
|
| 39 |
-
|
| 40 |
-
from io import BytesIO
|
| 41 |
-
buf = BytesIO()
|
| 42 |
-
img.save(buf, format="JPEG")
|
| 43 |
-
byte_im = buf.getvalue()
|
| 44 |
-
return byte_im
|
|
|
|
| 2 |
from diffusers import StableDiffusionPipeline
|
| 3 |
import torch
|
| 4 |
from PIL import Image
|
| 5 |
+
from io import BytesIO
|
| 6 |
|
| 7 |
+
# Load the model only once
|
| 8 |
@st.cache_resource
|
| 9 |
def load_model():
|
| 10 |
model_id = "runwayml/stable-diffusion-v1-5"
|
|
|
|
| 16 |
pipe = pipe.to("cuda" if torch.cuda.is_available() else "cpu")
|
| 17 |
return pipe
|
| 18 |
|
| 19 |
+
# Streamlit UI Code
|
| 20 |
+
st.set_page_config(page_title="Thumbnail Generator", layout="centered")
|
| 21 |
+
st.title("πΌοΈ AI Thumbnail Generator")
|
| 22 |
|
|
|
|
| 23 |
pipe = load_model()
|
| 24 |
|
| 25 |
+
prompt = st.text_input("π₯ Enter your prompt:", value="Minecraft NOOB vs PRO | bold text | fire background")
|
|
|
|
| 26 |
|
| 27 |
+
if st.button("π Generate"):
|
| 28 |
+
with st.spinner("Generating thumbnail..."):
|
| 29 |
+
image = pipe(prompt, guidance_scale=7.5).images[0]
|
| 30 |
+
st.image(image, caption="Generated Thumbnail", use_column_width=True)
|
|
|
|
|
|
|
| 31 |
|
| 32 |
+
# Download button
|
| 33 |
+
buf = BytesIO()
|
| 34 |
+
image.save(buf, format="JPEG")
|
| 35 |
+
byte_im = buf.getvalue()
|
| 36 |
+
st.download_button("Download Thumbnail", byte_im, file_name="thumbnail.jpg", mime="image/jpeg")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|