Spaces:
Sleeping
Sleeping
Update app.py
Browse files112345678910111256789101113141216171314151920212223161718192021222324252627282930import streamlit as stimport gradio as grimport torchfrom diffusers import DiffusionPipeline
@st.cache_resourcedef load_pipe(): pipe = DiffusionPipeline.from_pretrained( "stabilityai/stable-diffusion-xl-base-1.0", torch_dtype=torch.float16, variant="fp16", use_safetensors=True ).to("cuda")# Load model oncepipe = DiffusionPipeline.from_pretrained( "stabilityai/stable-diffusion-xl-base-1.0", torch_dtype=torch.float16, variant="fp16", use_safetensors=True).to("cuda") pipe.load_lora_weights("ZB-Tech/Text-to-Image") return pipe
st.title("🎨 AI Image Generator")prompt = st.text_input("Enter a prompt:", "Draw a picture of some coding on a screen with a horror background")# Load the LoRA weightspipe.load_lora_weights("ZB-Tech/Text-to-Image")
if st.button("Generate"): with st.spinner("Generating image..."): pipe = load_pipe() image = pipe(prompt).images[0] st.image(image, caption="Generated Image", use_column_width=True)# Define generation functiondef generate_image(prompt): image = pipe(prompt).images[0] return image
# Gradio UIdemo = gr.Interface( fn=generate_image, inputs=gr.Textbox(label="Enter a prompt", placeholder="e.g. Draw a picture of some coding on a screen with a horror background"), outputs=gr.Image(type="pil", label="Generated Image"), title="🎨 AI Image Generator", description="This demo uses Stable Diffusion XL with custom LoRA weights to generate images from your prompts.")
demo.launch()app.py+25-18