File size: 1,325 Bytes
9a9513f
 
 
 
 
ad64176
2a84b62
 
 
 
ad64176
9a9513f
b7cecc5
9a9513f
2a84b62
057b04c
ad64176
9a9513f
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
import gradio as gr
import tempfile
from PIL import Image
import os

# Assuming 'my_directory' is a directory in the current working directory
#directory_name = 'temp_dir'
#absolute_path1 = os.path.abspath(directory_name)
#print(f"The absolute path of '{directory_name}' is: {absolute_path1}")
#/home/user/app/temp_dir

# Access the environment variable
os.environ['GRADIO_TEMP_DIR'] = '/home/user/app/temp_dir'
print(os.environ['GRADIO_TEMP_DIR'])



def create():
    """
    Create a blank image with the specified dimensions, color, and filename.
    """
    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}")
    #filename = f'{temp_file.name}.png'
    # 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


with gr.Blocks(delete_cache=(2,2),
               theme=gr.themes.Base(radius_size="none")) as demo:
    with gr.Row():
        inp = gr.Textbox(placeholder="What is your name?")
        out = gr.Image(type='filepath')
    btn = gr.Button("GO!")
    btn.click(create,inputs=[],outputs=out)

demo.launch(debug=False)