embed / app.py
om-app's picture
Update app.py
d306302
raw
history blame
1.08 kB
import gradio as gr
import requests
import numpy as np
from PIL import Image
def enlarge_image(image, scale):
# convert image to bytes
img_byte_arr = image.tobytes()
# make request to DALL-E 2 API
response = requests.post("https://api.dall-e.com/v1/enlarge",
data=img_byte_arr,
params={"size": scale})
# get the image bytes from the response
image_bytes = response.content
# convert bytes to numpy array
img_np = np.array(Image.open(BytesIO(image_bytes)))
return img_np
# create the Gradio interface
input_image = gr.inputs.Image(label="Input Image")
scale = gr.inputs.Number(label="Scale", default=2)
output_image = gr.outputs.Image(label="Enlarged Image")
title = "DALL-E 2 Image Enlarger"
description = "Enlarges an image using DALL-E 2. Enter a scale factor and upload an image."
examples = [["examples/butterfly.jpg"]]
gr.Interface(fn=enlarge_image, inputs=[input_image, scale], outputs=output_image,
title=title, description=description, examples=examples).launch()