Spaces:
Sleeping
Sleeping
Commit ·
8bb6a15
1
Parent(s): 7521b47
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,28 +1,48 @@
|
|
|
|
|
|
|
|
| 1 |
import streamlit as st
|
| 2 |
-
from main import
|
| 3 |
-
|
| 4 |
-
|
| 5 |
-
|
| 6 |
-
|
| 7 |
-
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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.")
|