File size: 2,611 Bytes
9a9513f
 
 
89d1d2c
9a9513f
 
ad64176
2a84b62
 
 
 
ad64176
9a9513f
2e3488c
9706c5f
 
 
 
2a84b62
2e3488c
 
9706c5f
 
 
cf89b4e
 
9706c5f
 
057b04c
9706c5f
ad64176
dfdbf8a
 
f2b7407
 
 
 
 
9a9513f
 
 
 
 
 
 
 
 
 
 
 
 
 
 
dfdbf8a
 
 
8534fac
dfdbf8a
f2b7407
 
 
 
 
9a9513f
 
89d1d2c
9a9513f
 
 
 
 
dfdbf8a
9a9513f
8534fac
 
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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
import gradio as gr
import tempfile
from PIL import Image
import uuid 
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'] = '/data'
gradio_temp_dir = os.environ['GRADIO_TEMP_DIR'] 
print(f'GRADIO_TEMP_DIR is = {gradio_temp_dir}')
absolute_path1 = os.path.abspath(gradio_temp_dir)
print(f"The absolute path of gradio_temp_dir is = {absolute_path1}")

#os.makedirs('/data', exist_ok=True)

#current_directory = os.getcwd()
#print(f'current_directory is = {current_directory}')
#new_directory_name = 'temp_dir' #os.environ['GRADIO_TEMP_DIR']

# Constructing the path to the new directory
#new_directory_path = os.path.join(current_directory, new_directory_name)
#print(f"The path to the new directory is: {new_directory_path}")

#os.environ['GRADIO_TEMP_DIR'] = new_directory_path

######

# Get the path of the system's temporary directory
temp_directory = tempfile.gettempdir()
print(f"System's temporary directory is: {temp_directory}")


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')


    # Specify the directory you want to search in, e.g., the current directory
    directory = 'temp_dir'
    # List all entries in the directory
    entries = os.listdir(directory)
    print(f"listdir of temp_dir directory = {entries}")
    temp_directory_file_list = os.listdir(temp_directory)
    print(f'temp_directory_file_list is = {temp_directory_file_list}')
    return temp_file.name, temp_directory_file_list


with gr.Blocks(delete_cache=(5,10),
               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, inp])

#filepath11 = demo.move_resource_to_block_cache('/content/testing/mp333.png')
#print(f'filepath11 ^^^^^^= {filepath11}')
demo.launch(debug=False)