Spaces:
Runtime error
Runtime error
Singularity666
commited on
Commit
•
eded3b6
1
Parent(s):
3c7ffed
Update main.py
Browse files
main.py
CHANGED
@@ -1,82 +1,83 @@
|
|
1 |
import streamlit as st
|
|
|
|
|
2 |
import requests
|
3 |
from PIL import Image
|
4 |
from io import BytesIO
|
5 |
-
import getpass, os
|
6 |
-
import warnings
|
7 |
-
from stability_sdk import client
|
8 |
-
import stability_sdk.interfaces.gooseai.generation.generation_pb2 as generation
|
9 |
-
import replicate
|
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 |
with open(image_path, "rb") as img_file:
|
|
|
54 |
output = replicate.run(
|
55 |
"tencentarc/gfpgan:9283608cc6b7be6b65a8e44983db012355fde4132009bf99d976b2f0896856a3",
|
56 |
input={"img": img_file, "version": "v1.4", "scale": 16}
|
57 |
)
|
|
|
|
|
|
|
58 |
response = requests.get(output)
|
59 |
-
|
60 |
-
|
61 |
-
|
62 |
-
st.title("Image Generator and Upscaler")
|
63 |
-
|
64 |
-
prompt = st.text_input("Enter a prompt for the image generation")
|
65 |
-
|
66 |
-
if st.button("Generate and Upscale"):
|
67 |
-
if prompt:
|
68 |
-
img1 = generate_image(prompt)
|
69 |
|
70 |
-
|
71 |
-
|
72 |
-
|
73 |
|
74 |
-
|
75 |
-
|
76 |
-
|
|
|
|
|
|
|
|
|
|
|
77 |
|
78 |
-
|
79 |
-
|
80 |
-
img3.save('upscaled_image_gfpgan.png')
|
81 |
-
else:
|
82 |
-
st.write("Please enter a prompt")
|
|
|
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 |
+
|
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 |
+
# Set up environment variable for Replicate API Token
|
41 |
+
os.environ['REPLICATE_API_TOKEN'] = 'r8_3V5WKOBwbbuL0DQGMliP0972IAVIBo62Lmi8I' # Replace with your actual API token
|
42 |
+
|
43 |
+
|
44 |
+
def upscale_image(image_path):
|
45 |
+
# Open the image file
|
46 |
+
|
47 |
+
|
48 |
+
|
49 |
+
|
50 |
+
|
51 |
+
|
52 |
+
|
53 |
+
|
54 |
+
|
55 |
with open(image_path, "rb") as img_file:
|
56 |
+
# Run the GFPGAN model
|
57 |
output = replicate.run(
|
58 |
"tencentarc/gfpgan:9283608cc6b7be6b65a8e44983db012355fde4132009bf99d976b2f0896856a3",
|
59 |
input={"img": img_file, "version": "v1.4", "scale": 16}
|
60 |
)
|
61 |
+
|
62 |
+
# The output is a URI of the processed image
|
63 |
+
# We will retrieve the image data and save it
|
64 |
response = requests.get(output)
|
65 |
+
img = Image.open(BytesIO(response.content))
|
66 |
+
img.save("upscaled.png") # Save the upscaled image
|
67 |
+
return img
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
68 |
|
69 |
+
def main():
|
70 |
+
st.title("Image Upscaling")
|
71 |
+
st.write("Upload an image and it will be upscaled.")
|
72 |
|
73 |
+
uploaded_file = st.file_uploader("Choose an image...", type="png")
|
74 |
+
if uploaded_file is not None:
|
75 |
+
with open("temp_img.png", "wb") as f:
|
76 |
+
f.write(uploaded_file.getbuffer())
|
77 |
+
st.success("Uploaded image successfully!")
|
78 |
+
if st.button("Upscale Image"):
|
79 |
+
img = upscale_image("temp_img.png")
|
80 |
+
st.image(img, caption='Upscaled Image', use_column_width=True)
|
81 |
|
82 |
+
if __name__ == "__main__":
|
83 |
+
main()
|
|
|
|
|
|