Spaces:
Runtime error
Runtime error
File size: 1,507 Bytes
59864f6 eded3b6 59864f6 3c7ffed eded3b6 59864f6 eded3b6 59864f6 eded3b6 59864f6 eded3b6 3c7ffed eded3b6 3c7ffed eded3b6 3c7ffed eded3b6 |
1 2 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 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 |
import streamlit as st
import replicate
import os
import requests
from PIL import Image
from io import BytesIO
# Set up environment variable for Replicate API Token
os.environ['REPLICATE_API_TOKEN'] = 'r8_3V5WKOBwbbuL0DQGMliP0972IAVIBo62Lmi8I' # Replace with your actual API token
def upscale_image(image_path):
# Open the image file
with open(image_path, "rb") as img_file:
# Run the GFPGAN model
output = replicate.run(
"tencentarc/gfpgan:9283608cc6b7be6b65a8e44983db012355fde4132009bf99d976b2f0896856a3",
input={"img": img_file, "version": "v1.4", "scale": 16}
)
# The output is a URI of the processed image
# We will retrieve the image data and save it
response = requests.get(output)
img = Image.open(BytesIO(response.content))
img.save("upscaled.png") # Save the upscaled image
return img
def main():
st.title("Image Upscaling")
st.write("Upload an image and it will be upscaled.")
uploaded_file = st.file_uploader("Choose an image...", type="png")
if uploaded_file is not None:
with open("temp_img.png", "wb") as f:
f.write(uploaded_file.getbuffer())
st.success("Uploaded image successfully!")
if st.button("Upscale Image"):
img = upscale_image("temp_img.png")
st.image(img, caption='Upscaled Image', use_column_width=True)
if __name__ == "__main__":
main()
|