DetectiveShadow commited on
Commit
bc11304
·
verified ·
1 Parent(s): ebadd3a

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +25 -18
app.py CHANGED
@@ -1,23 +1,30 @@
1
- import streamlit as st
2
  import torch
3
  from diffusers import DiffusionPipeline
4
 
5
- @st.cache_resource
6
- def load_pipe():
7
- pipe = DiffusionPipeline.from_pretrained(
8
- "stabilityai/stable-diffusion-xl-base-1.0",
9
- torch_dtype=torch.float16,
10
- variant="fp16",
11
- use_safetensors=True
12
- ).to("cuda")
13
- pipe.load_lora_weights("ZB-Tech/Text-to-Image")
14
- return pipe
15
 
16
- st.title("🎨 AI Image Generator")
17
- prompt = st.text_input("Enter a prompt:", "Draw a picture of some coding on a screen with a horror background")
18
 
19
- if st.button("Generate"):
20
- with st.spinner("Generating image..."):
21
- pipe = load_pipe()
22
- image = pipe(prompt).images[0]
23
- st.image(image, caption="Generated Image", use_column_width=True)
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
  import torch
3
  from diffusers import DiffusionPipeline
4
 
5
+ # Load model once
6
+ pipe = DiffusionPipeline.from_pretrained(
7
+ "stabilityai/stable-diffusion-xl-base-1.0",
8
+ torch_dtype=torch.float16,
9
+ variant="fp16",
10
+ use_safetensors=True
11
+ ).to("cuda")
 
 
 
12
 
13
+ # Load the LoRA weights
14
+ pipe.load_lora_weights("ZB-Tech/Text-to-Image")
15
 
16
+ # Define generation function
17
+ def generate_image(prompt):
18
+ image = pipe(prompt).images[0]
19
+ return image
20
+
21
+ # Gradio UI
22
+ demo = gr.Interface(
23
+ fn=generate_image,
24
+ inputs=gr.Textbox(label="Enter a prompt", placeholder="e.g. Draw a picture of some coding on a screen with a horror background"),
25
+ outputs=gr.Image(type="pil", label="Generated Image"),
26
+ title="🎨 AI Image Generator",
27
+ description="This demo uses Stable Diffusion XL with custom LoRA weights to generate images from your prompts."
28
+ )
29
+
30
+ demo.launch()