Singularity666 commited on
Commit
59864f6
1 Parent(s): d527201

Upload 3 files

Browse files
Files changed (3) hide show
  1. app.py +41 -0
  2. main.py +41 -0
  3. requirements.txt +4 -0
app.py ADDED
@@ -0,0 +1,41 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ import replicate
3
+ import os
4
+ import requests
5
+ from PIL import Image
6
+ from io import BytesIO
7
+
8
+ # Set up environment variable for Replicate API Token
9
+ os.environ['REPLICATE_API_TOKEN'] = 'r8_3V5WKOBwbbuL0DQGMliP0972IAVIBo62Lmi8I' # Replace with your actual API token
10
+
11
+ def upscale_image(image_path):
12
+ # Open the image file
13
+ with open(image_path, "rb") as img_file:
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("temp_img.png", "wb") as f:
34
+ f.write(uploaded_file.getbuffer())
35
+ st.success("Uploaded image successfully!")
36
+ if st.button("Upscale Image"):
37
+ img = upscale_image("temp_img.png")
38
+ st.image(img, caption='Upscaled Image', use_column_width=True)
39
+
40
+ if __name__ == "__main__":
41
+ main()
main.py ADDED
@@ -0,0 +1,41 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ import replicate
3
+ import os
4
+ import requests
5
+ from PIL import Image
6
+ from io import BytesIO
7
+
8
+ # Set up environment variable for Replicate API Token
9
+ os.environ['REPLICATE_API_TOKEN'] = 'r8_3V5WKOBwbbuL0DQGMliP0972IAVIBo62Lmi8I' # Replace with your actual API token
10
+
11
+ def upscale_image(image_path):
12
+ # Open the image file
13
+ with open(image_path, "rb") as img_file:
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("temp_img.png", "wb") as f:
34
+ f.write(uploaded_file.getbuffer())
35
+ st.success("Uploaded image successfully!")
36
+ if st.button("Upscale Image"):
37
+ img = upscale_image("temp_img.png")
38
+ st.image(img, caption='Upscaled Image', use_column_width=True)
39
+
40
+ if __name__ == "__main__":
41
+ main()
requirements.txt ADDED
@@ -0,0 +1,4 @@
 
 
 
 
 
1
+ streamlit
2
+ Pillow
3
+ requests
4
+ replicate