File size: 817 Bytes
bb65e5f
 
835a781
 
 
 
 
 
 
 
bb65e5f
 
 
 
 
 
 
10b4930
bb65e5f
 
 
10b4930
835a781
 
 
fc2cd82
bb65e5f
 
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
import gradio as gr

def list_attributes_and_values(obj):
    attributes = dir(obj)
    for attr in attributes:
        # Filter out special (magic) methods and attributes
        if not attr.startswith('__'):
            value = getattr(obj, attr)
            print(f"{attr}: {value}")

def append_text_to_file(text):
    file_path = 'text_file.txt'
    with open(file_path, 'a') as file:
        file.write(text + '\n')
    with open(file_path, 'r') as file:
        new_content = file.read()
        print(new_content)
    return file_path

with gr.Blocks() as demo:
    tb_input = gr.Textbox(label='enter some text')
    fi_output = gr.File(type='binary')
    
    list_attributes_and_values(fi_output)
    
    tb_input.submit(append_text_to_file, inputs=tb_input, outputs=fi_output)
    
demo.launch(debug=True)