Spaces:
Running
Running
import gradio as gr | |
import pandas as pd | |
from utils import * | |
def infer(input_file: str): | |
clean_cache() | |
try: | |
data_list = eval(f'encoder_{MODE["from"]}')(input_file) | |
output_file = eval(f'decoder_{MODE["to"]}')(data_list) | |
return output_file, pd.DataFrame(data_list) | |
except Exception as e: | |
return None, pd.DataFrame([{"Please upload a standard data file": f"{e}"}]) | |
if __name__ == "__main__": | |
with gr.Blocks() as demo: | |
for item in TAB_CONFIG: | |
types = item.split(" β ") | |
with gr.Tab(item) as tab: | |
with gr.Row(): | |
with gr.Column(): | |
option = gr.Dropdown( | |
choices=[ | |
f"{types[0]} β {types[1]}", | |
f"{types[0]} β {types[1]}", | |
], | |
label="Mode", | |
value=f"{types[0]} β {types[1]}", | |
) | |
input_file = gr.components.File( | |
type="filepath", | |
label="Upload input file", | |
file_types=[f".{types[0]}", f".{types[1]}"], | |
) | |
convert_btn = gr.Button("Convert") | |
with gr.Column(): | |
output_file = gr.components.File( | |
type="filepath", label="Download output file" | |
) | |
data_viewer = gr.Dataframe(label="Data viewer") | |
option.change(change_mode, inputs=option) | |
tab.select(change_mode, inputs=option) | |
convert_btn.click( | |
infer, inputs=input_file, outputs=[output_file, data_viewer] | |
) | |
gr.Markdown( | |
""" | |
## Supported JSON format | |
``` | |
[ | |
{ | |
"key1": "val11", | |
"key2": "val12", | |
... | |
}, | |
{ | |
"key1": "val21", | |
"key2": "val22", | |
... | |
}, | |
... | |
] | |
``` | |
## Supported jsonl format | |
``` | |
{"key1": "val11", "key2": "val12", ...} | |
{"key1": "val21", "key2": "val22", ...} | |
... | |
``` | |
## Supported CSV format | |
``` | |
key1, key2, ... | |
val11, val12, ... | |
val21, val22, ... | |
... | |
``` | |
""" | |
) | |
demo.launch() | |