Spaces:
Runtime error
Runtime error
Commit ·
c844544
1
Parent(s): 59864f6
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,41 +1,24 @@
|
|
| 1 |
import streamlit as st
|
| 2 |
-
import
|
| 3 |
-
import
|
| 4 |
-
import requests
|
| 5 |
-
from PIL import Image
|
| 6 |
-
from io import BytesIO
|
| 7 |
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
# Run the GFPGAN model
|
| 15 |
-
output = replicate.run(
|
| 16 |
-
"tencentarc/gfpgan:9283608cc6b7be6b65a8e44983db012355fde4132009bf99d976b2f0896856a3",
|
| 17 |
-
input={"img": img_file, "version": "v1.4", "scale": 16}
|
| 18 |
-
)
|
| 19 |
-
|
| 20 |
-
# The output is a URI of the processed image
|
| 21 |
-
# We will retrieve the image data and save it
|
| 22 |
-
response = requests.get(output)
|
| 23 |
-
img = Image.open(BytesIO(response.content))
|
| 24 |
-
img.save("upscaled.png") # Save the upscaled image
|
| 25 |
-
return img
|
| 26 |
-
|
| 27 |
-
def main():
|
| 28 |
-
st.title("Image Upscaling")
|
| 29 |
-
st.write("Upload an image and it will be upscaled.")
|
| 30 |
|
|
|
|
| 31 |
uploaded_file = st.file_uploader("Choose an image...", type="png")
|
| 32 |
if uploaded_file is not None:
|
| 33 |
-
with open("
|
| 34 |
-
f.write(uploaded_file.
|
| 35 |
-
|
| 36 |
-
|
| 37 |
-
|
| 38 |
-
|
|
|
|
| 39 |
|
| 40 |
if __name__ == "__main__":
|
| 41 |
-
|
|
|
|
| 1 |
import streamlit as st
|
| 2 |
+
from main import upscale_image
|
| 3 |
+
import base64
|
|
|
|
|
|
|
|
|
|
| 4 |
|
| 5 |
+
def get_image_download_link(img_path, filename="upscaled_image.png"):
|
| 6 |
+
with open(img_path, 'rb') as f:
|
| 7 |
+
bytes = f.read()
|
| 8 |
+
b64 = base64.b64encode(bytes).decode()
|
| 9 |
+
href = f'<a href="data:file/octet-stream;base64,{b64}" download=\'{filename}\'>Click here to download the upscaled image</a>'
|
| 10 |
+
return href
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 11 |
|
| 12 |
+
def app():
|
| 13 |
uploaded_file = st.file_uploader("Choose an image...", type="png")
|
| 14 |
if uploaded_file is not None:
|
| 15 |
+
with open("uploaded.png", "wb") as f:
|
| 16 |
+
f.write(uploaded_file.getvalue())
|
| 17 |
+
|
| 18 |
+
upscale_image("uploaded.png") # This will create "upscaled.png"
|
| 19 |
+
|
| 20 |
+
st.image("upscaled.png", caption="Upscaled Image", use_column_width=True)
|
| 21 |
+
st.markdown(get_image_download_link("upscaled.png"), unsafe_allow_html=True)
|
| 22 |
|
| 23 |
if __name__ == "__main__":
|
| 24 |
+
app()
|