Spaces:
Runtime error
Runtime error
Commit
•
6ab762d
1
Parent(s):
edbcada
Update app.py
Browse files
app.py
CHANGED
@@ -1,32 +1,36 @@
|
|
1 |
import streamlit as st
|
2 |
import torch
|
3 |
from diffusers import StableDiffusionPipeline
|
4 |
-
import matplotlib.pyplot as plt
|
5 |
|
6 |
-
st.title('Text-to-Image Generation using Stable Diffusion')
|
7 |
-
|
8 |
-
# Load the diffusion model
|
9 |
model_id1 = "runwayml/stable-diffusion-v1-5"
|
10 |
pipe = StableDiffusionPipeline.from_pretrained(model_id1, torch_dtype=torch.float16, use_safetensors=True)
|
11 |
pipe = pipe.to("cuda")
|
12 |
|
13 |
-
|
14 |
-
|
15 |
-
|
16 |
-
|
17 |
-
|
|
|
|
|
|
|
|
|
18 |
img = pipe(**params).images
|
19 |
return img[0], img[1]
|
20 |
|
21 |
-
# Create Streamlit interface
|
22 |
-
st.sidebar.subheader("Enter Prompts")
|
23 |
-
prompt = st.sidebar.text_area("Enter Prompt")
|
24 |
-
negative_prompt = st.sidebar.text_area("Enter Negative Prompt")
|
25 |
-
num_inference_steps = st.sidebar.slider("Number of Inference Steps", 1, 100, 50)
|
26 |
-
weight = st.sidebar.slider("Image Width", 512, 640, 640)
|
27 |
|
28 |
-
|
29 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
30 |
|
31 |
-
|
32 |
-
|
|
|
1 |
import streamlit as st
|
2 |
import torch
|
3 |
from diffusers import StableDiffusionPipeline
|
|
|
4 |
|
|
|
|
|
|
|
5 |
model_id1 = "runwayml/stable-diffusion-v1-5"
|
6 |
pipe = StableDiffusionPipeline.from_pretrained(model_id1, torch_dtype=torch.float16, use_safetensors=True)
|
7 |
pipe = pipe.to("cuda")
|
8 |
|
9 |
+
def generate_image(prompt, negative_prompt, num_inference_steps=50, width=640):
|
10 |
+
params = {
|
11 |
+
'prompt': prompt,
|
12 |
+
'num_inference_steps': num_inference_steps,
|
13 |
+
'num_images_per_prompt': 2,
|
14 |
+
'height': int(1.2 * width),
|
15 |
+
'width': width,
|
16 |
+
'negative_prompt': negative_prompt
|
17 |
+
}
|
18 |
img = pipe(**params).images
|
19 |
return img[0], img[1]
|
20 |
|
|
|
|
|
|
|
|
|
|
|
|
|
21 |
|
22 |
+
def main():
|
23 |
+
st.title("Diffuser Image Generator")
|
24 |
+
prompt = st.text_input("Enter the prompt:")
|
25 |
+
negative_prompt = st.text_input("Enter the negative prompt:")
|
26 |
+
num_inference_steps = st.slider("Number of inference steps", 1, 100, 50)
|
27 |
+
width = st.slider("Width", 512, 640, 640)
|
28 |
+
|
29 |
+
if st.button("Generate Image"):
|
30 |
+
image1, image2 = generate_image(prompt, negative_prompt, num_inference_steps, width)
|
31 |
+
st.image(image1, caption="Generated Image 1", use_column_width=True)
|
32 |
+
st.image(image2, caption="Generated Image 2", use_column_width=True)
|
33 |
+
|
34 |
|
35 |
+
if __name__ == "__main__":
|
36 |
+
main()
|