Update app.py
Browse files
app.py
CHANGED
@@ -6,9 +6,14 @@ import torch
|
|
6 |
# Load the diffusion pipeline model
|
7 |
@st.cache_resource
|
8 |
def load_pipeline():
|
9 |
-
|
10 |
-
|
11 |
-
|
|
|
|
|
|
|
|
|
|
|
12 |
|
13 |
pipe = load_pipeline()
|
14 |
|
@@ -20,12 +25,18 @@ user_prompt = st.text_input("Enter your image prompt", value="a photo of Yash Ko
|
|
20 |
|
21 |
# Button to generate the image
|
22 |
if st.button("Generate Image"):
|
23 |
-
if user_prompt:
|
24 |
with st.spinner("Generating image..."):
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
|
|
|
|
|
|
|
30 |
else:
|
31 |
-
|
|
|
|
|
|
|
|
6 |
# Load the diffusion pipeline model
|
7 |
@st.cache_resource
|
8 |
def load_pipeline():
|
9 |
+
try:
|
10 |
+
pipe = DiffusionPipeline.from_pretrained("stabilityai/stable-diffusion-xl-base-1.0", torch_dtype=torch.float16)
|
11 |
+
pipe.load_lora_weights("kothariyashhh/GenAi-Texttoimage")
|
12 |
+
pipe = pipe.to("cuda") # Move model to GPU if available
|
13 |
+
return pipe
|
14 |
+
except Exception as e:
|
15 |
+
st.error(f"Error loading model: {e}")
|
16 |
+
return None
|
17 |
|
18 |
pipe = load_pipeline()
|
19 |
|
|
|
25 |
|
26 |
# Button to generate the image
|
27 |
if st.button("Generate Image"):
|
28 |
+
if user_prompt and pipe:
|
29 |
with st.spinner("Generating image..."):
|
30 |
+
try:
|
31 |
+
# Generate the image
|
32 |
+
image = pipe(user_prompt).images[0]
|
33 |
+
|
34 |
+
# Display the generated image
|
35 |
+
st.image(image, caption="Generated Image", use_column_width=True)
|
36 |
+
except Exception as e:
|
37 |
+
st.error(f"Error generating image: {e}")
|
38 |
else:
|
39 |
+
if not pipe:
|
40 |
+
st.error("Model not loaded. Please check the logs.")
|
41 |
+
else:
|
42 |
+
st.error("Please enter a valid prompt.")
|