File size: 1,020 Bytes
bb65e5f
 
da58160
c2b39ba
da58160
c2b39ba
14990c7
835a781
bb65e5f
 
 
 
 
 
 
14990c7
 
 
 
bb65e5f
 
 
f22a924
14990c7
 
f22a924
fc2cd82
c2b39ba
14990c7
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
29
30
31
import gradio as gr

def list_attributes_and_values():
    attr = 'temp_files'
    value = getattr(fi_output, attr)
    for tmp in value:
        return f"[Click here to download the file](https://organizedprogrammers-test-file-editing.hf.space/file={tmp})"

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)
    with zipfile.ZipFile(zip_file_path, 'w') as zipf:
        zipf.write(file_path, os.path.basename(file_path))

    return zip_file_path})"

with gr.Blocks() as demo:
    tb_input = gr.Textbox(label='enter some text')
    global fi_output
    fi_output = gr.File(type='binary', visible=False)
    md_hypertext = gr.Markdown()
        
    tb_input.submit(append_text_to_file, inputs=tb_input, outputs=fi_output)

    fi_output.change(list_attributes_and_values, inputs=None, outputs=md_hypertext)
    
demo.launch(debug=True)