Bagda commited on
Commit
985c512
Β·
verified Β·
1 Parent(s): ad2b604

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +18 -24
app.py CHANGED
@@ -1,36 +1,30 @@
1
  import streamlit as st
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"
11
- pipe = StableDiffusionPipeline.from_pretrained(
12
- model_id,
13
- torch_dtype=torch.float16 if torch.cuda.is_available() else torch.float32,
14
- safety_checker=None
15
  )
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")
 
1
  import streamlit as st
 
 
2
  from PIL import Image
3
+ from transformers import AutoProcessor, KandinskyDecoderPipeline
4
+ import torch
5
 
 
6
  @st.cache_resource
7
  def load_model():
8
+ processor = AutoProcessor.from_pretrained("kandinsky-community/kandinsky-2-2-decoder")
9
+ model = KandinskyDecoderPipeline.from_pretrained(
10
+ "kandinsky-community/kandinsky-2-2-decoder",
11
+ torch_dtype=torch.float32,
 
12
  )
13
+ model.to("cpu")
14
+ return processor, model
 
 
 
 
15
 
16
+ st.set_page_config(page_title="Thumbnail AI - Kandinsky", layout="centered")
17
+ st.title("🎨 Kandinsky Thumbnail Generator")
18
 
19
+ prompt = st.text_input("πŸ“ Enter your thumbnail idea:", "Minecraft Hardcore NOOB vs PRO battle")
20
 
21
+ if st.button("🎬 Generate Image"):
22
+ with st.spinner("Loading model and generating..."):
23
+ processor, model = load_model()
24
+ image = model(prompt=prompt).images[0]
25
  st.image(image, caption="Generated Thumbnail", use_column_width=True)
26
+ st.success("βœ… Done!")
27
 
28
  # Download button
29
+ img_bytes = image.convert("RGB").tobytes("raw", "RGB")
30
+ st.download_button("Download Image", data=img_bytes, file_name="thumbnail.jpg", mime="image/jpeg")