tahirsher's picture
Create app.py
df51bb4 verified
raw
history blame
952 Bytes
import streamlit as st
from diffusers import DiffusionPipeline
from PIL import Image
import torch
# Load the diffusion pipeline model
@st.cache_resource
def load_pipeline():
pipe = DiffusionPipeline.from_pretrained("stabilityai/stable-diffusion-xl-base-1.0")
pipe.load_lora_weights("kothariyashhh/GenAi-Texttoimage")
return pipe
pipe = load_pipeline()
# Streamlit app
st.title("Text-to-Image Generation App")
# User input for prompt
user_prompt = st.text_input("Enter your image prompt", value="a photo of Yash Kothari with bike")
# Button to generate the image
if st.button("Generate Image"):
if user_prompt:
with st.spinner("Generating image..."):
# Generate the image
image = pipe(user_prompt).images[0]
# Display the generated image
st.image(image, caption="Generated Image", use_column_width=True)
else:
st.error("Please enter a valid prompt.")