Spaces:
Runtime error
Runtime error
import streamlit as st | |
import numpy as np | |
import PIL.Image | |
import base64 | |
from io import BytesIO | |
import os | |
import requests | |
import urllib.request | |
st.write("This app generates photos with the DALL-E Encoder. \n \n To use this app, simply upload a photo and click 'Generate'. \n \n This app is in Alpha so please be patient with it.") | |
st.title("Photo Editor V1.0") | |
def generate_image(image_path): | |
image = load_image(image_path) | |
st.image(image, use_column_width=True) | |
st.write("Generated image:") | |
generated_image = inpaint_image(image_path) | |
st.image(generated_image, use_column_width=True) | |
# st.write("Generated image:") | |
# generated_image = inpaint_image(image) | |
# st.image(generated_image, use_column_width=True) | |
# st.write("Generated image:") | |
# generated_image = inpaint_image(image) | |
# st.image(generated_image, use_column_width=True) | |
# st.write("Generated image:") | |
# generated_image = inpaint_image(image) | |
# st.image(generated_image, use_column_width=True) | |
# st.write("Generated image:") | |
# generated_image = inpaint_image(image) | |
# st.image(generated_image, use_column_width=True) | |
# st.write("Generated image:") | |
# generated_image = inpaint_image(image) | |
# st.image(generated_image, use_column_width=True) | |
# st.write("Generated image:") | |
# generated_image = inpaint_image(image) | |
# st.image(generated_image, use_column_width=True) | |
# st.write("Generated image:") | |
# generated_image = inpaint_image(image) | |
# st.image(generated_image, use_column_width=True) | |
# st.write("Generated image:") | |
# generated_image = inpaint_image(image) | |
# st.image(generated_image, use_column_width=True) | |
# st.write("Generated image:") | |
# generated_image = inpaint_image(image) | |
# st.image(generated_image, use_column_width=True) | |
# st.write("Generated image:") | |
# generated_image = inpaint_image(image) | |
# st.image(generated_image, use_column_width=True) | |
# st.write("Generated image:") | |
# generated_image = inpaint_image(image) | |
# st.image(generated_image, use_column_width=True) | |
# st.write("Generated image:") | |
# generated_image = inpaint_image(image) | |
# st.image(generated_image, use_column_width=True) | |
def load_image(image_path): | |
image = PIL.Image.open(image_path) | |
return np.array(image) | |
def inpaint_image(image_path): | |
# image = PIL.Image.fromarray(image) | |
# buffered = BytesIO() | |
# image.save(buffered, format="JPEG") | |
# encoded_image = base64.b64encode(buffered.getvalue()).decode("utf-8") | |
# response = requests.post( | |
# "https://api.deepai.org/api/inpaint", | |
# data={ | |
# "image": encoded_image, | |
# "filename": "image.jpg", | |
# }, | |
# headers={ | |
# "api-key": API_KEY, | |
# }, | |
# ) | |
# if response.status_code == 200: | |
# response_json = response.json() | |
# output_url = response_json["output_url"] | |
# response = requests.get(output_url) | |
# image = PIL.Image.open(BytesIO(response.content)) | |
# return np.array(image) | |
# else: | |
# st.error("Something went wrong. Please try again.") | |
url = "https://api.andersonrobotics.com/api/v1/generate" | |
payload = { | |
"prompt": "a boy and a girl are playing with a ball and a cat and a dog", | |
"num_samples": 1, | |
"num_return": 1, | |
"temperature": 1.0, | |
"top_k": 0, | |
"top_p": 0.0, | |
"model_name": "dall-e" | |
} | |
files = [ | |
('file', open(image_path, 'rb')) | |
] | |
headers = { | |
'Authorization': "Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VybmFtZSI6ImFkbWluIiwiZW1haWwiOiJhZG1pbkBhbmRlcnNvbnJvY2tldGljcy5jb20iLCJpYXQiOjE1OTYxNzE1MjB9.nHpKW8eNvfZQQbzDmwq7WjzvfzgT9T6DlL-YW8Fv1Zs" | |
} | |
response = requests.request("POST", url, headers=headers, data = payload, files = files) | |
print(response.text.encode('utf8')) | |
image_url = response.json()["data"][0] | |
urllib.request.urlretrieve(image_url, "image.png") | |
image = load_image("image.png") | |
return image | |
image_file = st.file_uploader("Upload an image", type=['jpg', 'png', 'jpeg']) | |
if image_file is not None: | |
generate_image(image_file) |