ysharma's picture
ysharma HF Staff
Update app.py
c7a2e27 verified
raw
history blame
1.13 kB
import gradio as gr
import tempfile
from PIL import Image
import os
# Get the path to the temporary directory
temp_dir = tempfile.gettempdir()
print(f"Temporary directory : {temp_dir}")
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')
# List all files in the temporary directory
print('_________________')
temp_files = os.listdir(temp_dir)
print(f"Temporary files and directories in '{temp_dir}':")
for file in temp_files:
print(file)
print('_________________')
return temp_file.name, temp_files
# usage:
with gr.Blocks(delete_cache=(2,4)) as demo:
with gr.Row():
tb = gr.Textbox()
out = gr.Image(type='filepath')
btn = gr.Button("GO!")
btn.click(create,inputs=[],outputs=[out, tb])
demo.launch()