Commit
·
30b12a2
1
Parent(s):
88de445
Update main.py
Browse files
main.py
CHANGED
@@ -1,11 +1,11 @@
|
|
1 |
-
# main.py
|
2 |
-
|
3 |
import streamlit as st
|
4 |
import os
|
5 |
import requests
|
6 |
from PIL import Image
|
7 |
from io import BytesIO
|
8 |
import replicate
|
|
|
|
|
9 |
|
10 |
# Configure your API keys here
|
11 |
CLIPDROP_API_KEY = '1143a102dbe21628248d4bb992b391a49dc058c584181ea72e17c2ccd49be9ca69ccf4a2b97fc82c89ff1029578abbea'
|
@@ -28,18 +28,34 @@ def generate_image_from_text(prompt):
|
|
28 |
r.raise_for_status()
|
29 |
|
30 |
def upscale_image_stable_diffusion(image_bytes):
|
31 |
-
|
32 |
-
|
33 |
-
|
34 |
-
|
35 |
-
|
36 |
-
|
37 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
38 |
|
39 |
-
|
40 |
-
return r.content
|
41 |
-
else:
|
42 |
-
r.raise_for_status()
|
43 |
|
44 |
def further_upscale_image(image_bytes):
|
45 |
# Run the GFPGAN model
|
|
|
|
|
|
|
1 |
import streamlit as st
|
2 |
import os
|
3 |
import requests
|
4 |
from PIL import Image
|
5 |
from io import BytesIO
|
6 |
import replicate
|
7 |
+
from stability_sdk import client
|
8 |
+
import stability_sdk.interfaces.gooseai.generation.generation_pb2 as generation
|
9 |
|
10 |
# Configure your API keys here
|
11 |
CLIPDROP_API_KEY = '1143a102dbe21628248d4bb992b391a49dc058c584181ea72e17c2ccd49be9ca69ccf4a2b97fc82c89ff1029578abbea'
|
|
|
28 |
r.raise_for_status()
|
29 |
|
30 |
def upscale_image_stable_diffusion(image_bytes):
|
31 |
+
# Set up environment variables
|
32 |
+
os.environ['STABILITY_HOST'] = 'grpc.stability.ai:443'
|
33 |
+
os.environ['STABILITY_KEY'] = STABLE_DIFFUSION_API_KEY
|
34 |
+
|
35 |
+
# Set up the connection to the API
|
36 |
+
stability_api = client.StabilityInference(
|
37 |
+
key=os.environ['STABILITY_KEY'],
|
38 |
+
upscale_engine="stable-diffusion-x4-latent-upscaler",
|
39 |
+
verbose=True,
|
40 |
+
)
|
41 |
+
|
42 |
+
# Open the image from bytes
|
43 |
+
img = Image.open(BytesIO(image_bytes))
|
44 |
+
|
45 |
+
# Call the upscale API
|
46 |
+
answers = stability_api.upscale(init_image=img)
|
47 |
+
|
48 |
+
# Process the response
|
49 |
+
upscaled_img_bytes = None
|
50 |
+
for resp in answers:
|
51 |
+
for artifact in resp.artifacts:
|
52 |
+
if artifact.type == generation.ARTIFACT_IMAGE:
|
53 |
+
upscaled_img = Image.open(BytesIO(artifact.binary))
|
54 |
+
upscaled_img_bytes = BytesIO()
|
55 |
+
upscaled_img.save(upscaled_img_bytes, format='PNG')
|
56 |
+
upscaled_img_bytes = upscaled_img_bytes.getvalue()
|
57 |
|
58 |
+
return upscaled_img_bytes
|
|
|
|
|
|
|
59 |
|
60 |
def further_upscale_image(image_bytes):
|
61 |
# Run the GFPGAN model
|