gradio/demo/zip_to_json.py

21 lines
473 B
Python
Raw Normal View History

2020-08-20 19:57:07 +08:00
import gradio as gr
from zipfile import ZipFile
2020-08-28 23:56:03 +08:00
2020-08-20 19:57:07 +08:00
def zip_to_json(file_obj):
files = []
with ZipFile(file_obj.name) as zfile:
for zinfo in zfile.infolist():
files.append({
"name": zinfo.filename,
"file_size": zinfo.file_size,
"compressed_size": zinfo.compress_size,
})
return files
2020-08-28 23:56:03 +08:00
2020-11-11 22:15:53 +08:00
iface = gr.Interface(zip_to_json, "file", "json")
2020-08-28 23:56:03 +08:00
2020-11-11 22:15:53 +08:00
if __name__ == "__main__":
iface.launch()