Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,31 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import streamlit as st
|
2 |
+
from diffusers import DiffusionPipeline
|
3 |
+
from PIL import Image
|
4 |
+
import torch
|
5 |
+
|
6 |
+
# Load the diffusion pipeline model
|
7 |
+
@st.cache_resource
|
8 |
+
def load_pipeline():
|
9 |
+
pipe = DiffusionPipeline.from_pretrained("stabilityai/stable-diffusion-xl-base-1.0")
|
10 |
+
pipe.load_lora_weights("kothariyashhh/GenAi-Texttoimage")
|
11 |
+
return pipe
|
12 |
+
|
13 |
+
pipe = load_pipeline()
|
14 |
+
|
15 |
+
# Streamlit app
|
16 |
+
st.title("Text-to-Image Generation App")
|
17 |
+
|
18 |
+
# User input for prompt
|
19 |
+
user_prompt = st.text_input("Enter your image prompt", value="a photo of Yash Kothari with bike")
|
20 |
+
|
21 |
+
# Button to generate the image
|
22 |
+
if st.button("Generate Image"):
|
23 |
+
if user_prompt:
|
24 |
+
with st.spinner("Generating image..."):
|
25 |
+
# Generate the image
|
26 |
+
image = pipe(user_prompt).images[0]
|
27 |
+
|
28 |
+
# Display the generated image
|
29 |
+
st.image(image, caption="Generated Image", use_column_width=True)
|
30 |
+
else:
|
31 |
+
st.error("Please enter a valid prompt.")
|