ysharma's picture
ysharma HF Staff
Update app.py
9f34051 verified
raw
history blame
678 Bytes
import gradio as gr
import tempfile
from PIL import Image
def create():
color='blue'
width=512
height=512
# Create a temporary file
temp_file = tempfile.NamedTemporaryFile(delete=False, suffix=".png")
print(f"Temporary file created at: {temp_file.name}")
# Create a new image with the given mode and size
image = Image.new("RGB", (width, height), color)
# Save the image to disk
image.save(temp_file, format='PNG')
return temp_file.name
# usage:
with gr.Blocks(delete_cache=(2,4)) as demo:
out = gr.Image(type='filepath')
btn = gr.Button("GO!")
btn.click(create,inputs=[],outputs=out)
demo.launch()