shubham5027 commited on
Commit
5c4a3bd
·
1 Parent(s): be9d345

Upload 2 files

Browse files
Files changed (2) hide show
  1. app.py +41 -0
  2. requirements.txt +4 -0
app.py ADDED
@@ -0,0 +1,41 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ from diffusers import StableDiffusionPipeline
3
+ import torch
4
+ import transformers
5
+ from transformers import pipeline
6
+ pipe = StableDiffusionPipeline.from_pretrained('runwayml/stable-diffusion-v1-5', torch_dtype=torch.float16)
7
+
8
+ def generate_image(prompt):
9
+
10
+ pipe = pipe.to("cuda")
11
+
12
+ image = pipe(prompt).images[0]
13
+ return image
14
+
15
+ def main():
16
+ st.title("Text-to-Image Generation with Stable Diffusion")
17
+
18
+
19
+ prompt = st.text_input("Enter a prompt for image generation:")
20
+
21
+ if st.button("Generate Image"):
22
+ if prompt:
23
+
24
+ generated_image = generate_image(prompt)
25
+
26
+
27
+ st.image(generated_image, caption="Generated Image", use_column_width=True, channels="RGB")
28
+
29
+
30
+ generated_image.save("generated_image.png")
31
+
32
+
33
+ st.markdown(get_image_download_link(generated_image), unsafe_allow_html=True)
34
+
35
+ def get_image_download_link(image):
36
+ """Generate a link allowing the image to be downloaded"""
37
+ href = f'<a href="generated_image.png" download>Click here to download the image</a>'
38
+ return href
39
+
40
+ if __name__ == "__main__":
41
+ main()
requirements.txt ADDED
@@ -0,0 +1,4 @@
 
 
 
 
 
1
+ diffusers==0.25.0
2
+ streamlit==1.20.0
3
+ torch==2.1.2
4
+ transformers==4.36.2