Spaces:
Sleeping
Sleeping
Commit ·
3f00a5c
1
Parent(s): 5c84876
Update main.py
Browse files
main.py
CHANGED
|
@@ -1,6 +1,7 @@
|
|
| 1 |
import streamlit as st
|
| 2 |
import os
|
| 3 |
import requests
|
|
|
|
| 4 |
from PIL import Image
|
| 5 |
from io import BytesIO
|
| 6 |
import replicate
|
|
@@ -90,13 +91,21 @@ def further_upscale_image(image_bytes):
|
|
| 90 |
try:
|
| 91 |
print("Saving upscaled image...")
|
| 92 |
img = Image.open(BytesIO(response.content))
|
| 93 |
-
|
|
|
|
| 94 |
except Exception as e:
|
| 95 |
print("Error saving upscaled image: ", e)
|
| 96 |
raise e
|
| 97 |
|
| 98 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 99 |
|
|
|
|
| 100 |
|
| 101 |
def main():
|
| 102 |
st.title("Image Generation and Upscaling")
|
|
@@ -112,9 +121,9 @@ def main():
|
|
| 112 |
upscaled_image_bytes = upscale_image_esrgan(image_bytes)
|
| 113 |
|
| 114 |
st.success("Further upscaling image with GFPGAN...")
|
| 115 |
-
|
| 116 |
|
| 117 |
-
st.
|
| 118 |
|
| 119 |
if __name__ == "__main__":
|
| 120 |
-
main()
|
|
|
|
| 1 |
import streamlit as st
|
| 2 |
import os
|
| 3 |
import requests
|
| 4 |
+
import base64
|
| 5 |
from PIL import Image
|
| 6 |
from io import BytesIO
|
| 7 |
import replicate
|
|
|
|
| 91 |
try:
|
| 92 |
print("Saving upscaled image...")
|
| 93 |
img = Image.open(BytesIO(response.content))
|
| 94 |
+
output_file = "upscaled.png"
|
| 95 |
+
img.save(output_file) # Save the upscaled image
|
| 96 |
except Exception as e:
|
| 97 |
print("Error saving upscaled image: ", e)
|
| 98 |
raise e
|
| 99 |
|
| 100 |
+
# Create a function to make download link
|
| 101 |
+
def create_download_link(file, filename):
|
| 102 |
+
with open(file, 'rb') as f:
|
| 103 |
+
bytes = f.read()
|
| 104 |
+
b64 = base64.b64encode(bytes).decode()
|
| 105 |
+
href = f'<a href="data:file/octet-stream;base64,{b64}" download="{filename}">Download File</a>'
|
| 106 |
+
return href
|
| 107 |
|
| 108 |
+
return create_download_link(output_file, "upscaled_image.png")
|
| 109 |
|
| 110 |
def main():
|
| 111 |
st.title("Image Generation and Upscaling")
|
|
|
|
| 121 |
upscaled_image_bytes = upscale_image_esrgan(image_bytes)
|
| 122 |
|
| 123 |
st.success("Further upscaling image with GFPGAN...")
|
| 124 |
+
download_link = further_upscale_image(upscaled_image_bytes)
|
| 125 |
|
| 126 |
+
st.markdown(download_link, unsafe_allow_html=True)
|
| 127 |
|
| 128 |
if __name__ == "__main__":
|
| 129 |
+
main()
|