Singularity666 commited on
Commit
8bb6a15
1 Parent(s): 7521b47

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +47 -27
app.py CHANGED
@@ -1,28 +1,48 @@
 
 
1
  import streamlit as st
2
- from main import generate_image_from_text, upscale_image_esrgan, further_upscale_image
3
-
4
- def main():
5
- st.title("Image Generation and Upscaling")
6
- st.write("Enter a text prompt and an image will be generated and upscaled.")
7
-
8
- prompt = st.text_input("Enter a textual prompt to generate an image...")
9
-
10
- if prompt:
11
- progress_bar = st.progress(0)
12
-
13
- st.write("Generating image from text prompt...")
14
- image_bytes = generate_image_from_text(prompt)
15
- progress_bar.progress(33)
16
-
17
- st.write("Upscaling image with ESRGAN...")
18
- upscaled_image_bytes = upscale_image_esrgan(image_bytes)
19
- progress_bar.progress(66)
20
-
21
- st.write("Further upscaling image with GFPGAN...")
22
- download_link = further_upscale_image(upscaled_image_bytes)
23
- progress_bar.progress(100)
24
-
25
- st.markdown(download_link, unsafe_allow_html=True)
26
-
27
- if __name__ == "__main__":
28
- main()
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # app.py
2
+
3
  import streamlit as st
4
+ from main import generate_and_upscale_image
5
+ from PIL import Image
6
+ import io
7
+
8
+ # Display title and instructions
9
+ st.title("Text to Image Upscaling")
10
+ st.write("Please enter a text prompt, and we will generate and upscale an image based on it.")
11
+
12
+ # User input for text prompt
13
+ text_prompt = st.text_input('Enter your text prompt here:')
14
+
15
+ # User input for API keys
16
+ clipdrop_api_key = st.text_input('Enter your ClipDrop API key:', type="password")
17
+ stability_api_key = st.text_input('Enter your Stability API key:', type="password")
18
+ replicate_api_token = st.text_input('Enter your Replicate API token:', type="password")
19
+
20
+ # When the button is clicked, the processing functions are called with the user's input
21
+ if st.button('Generate and Upscale Image'):
22
+
23
+ st.write("Processing... Please wait, this may take a while.")
24
+
25
+ # Calls function from main.py and passes user input
26
+ upscaled_image = generate_and_upscale_image(
27
+ text_prompt=text_prompt,
28
+ clipdrop_api_key=clipdrop_api_key,
29
+ stability_api_key=stability_api_key,
30
+ replicate_api_token=replicate_api_token,
31
+ )
32
+
33
+ # Show the resulting image
34
+ st.image(upscaled_image, caption='Your upscaled image')
35
+
36
+ # Option to download image
37
+ buffered = io.BytesIO()
38
+ upscaled_image.save(buffered, format="PNG")
39
+ img_str = buffered.getvalue()
40
+ try:
41
+ st.download_button(
42
+ label="Download Image",
43
+ data=img_str,
44
+ file_name='upscaled_image.png',
45
+ mime='image/png',
46
+ )
47
+ except Exception as e:
48
+ st.write("Error in downloading the image.")