Download app.py from OrganizedProgrammers/Test_File_Editing: direct link, hf CLI and curl.
- Browser
- Download file 1.22 kB
-
https://huggingface.co/spaces/OrganizedProgrammers/Test_File_Editing/resolve/e8fc88ead9b894b515a7adbb8ec782a691dd33dc/app.py
- Command line
-
hf download hf://spaces/OrganizedProgrammers/Test_File_Editing@e8fc88ead9b894b515a7adbb8ec782a691dd33dc/app.py
-
curl -L -o app.py https://huggingface.co/spaces/OrganizedProgrammers/Test_File_Editing/resolve/e8fc88ead9b894b515a7adbb8ec782a691dd33dc/app.py
1.22 kB
| import zipfile | |
| import os | |
| import gradio as gr | |
| global value | |
| value = set() | |
| def list_attributes_and_values(): | |
| global value | |
| attr = 'temp_files' | |
| new_value = getattr(fi_output, attr) | |
| print(f"value: {value}\nnew value: {new_value}") | |
| tmp = list(new_value - value)[0] | |
| value = set(new_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' | |
| zip_file_path = 'text_file.zip' | |
| 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) |