Spaces:
Runtime error
Runtime error
| import gradio as gr | |
| import pandas as pd | |
| import json | |
| keys = ['review', 'domain', 'label'] | |
| keys_types = ["str", "str", "number"] | |
| path = 'data/' | |
| default_json = path + 'hola_0.jsonl' | |
| df_test = pd.DataFrame({'review': 'hola', 'domain': 'house', 'label': 1}, index=[0]) | |
| data, df = None, None | |
| def process_jsonl(temp_file): | |
| json_file = default_json | |
| if isinstance(temp_file, str): | |
| json_file = temp_file | |
| df = pd.read_json(json_file, lines=True) | |
| print(df[:9], df.shape) | |
| return df | |
| with gr.Blocks() as demo: | |
| upload_button = gr.UploadButton( | |
| label="upload jsonl", | |
| file_types = ['.jsonl', '.json'], | |
| # live=True, | |
| file_count = "single" | |
| ) | |
| table = gr.Dataframe( | |
| headers=keys, | |
| datatype=keys_types, | |
| col_count=(3, "fixed"), | |
| row_count=(6, 'fixed'), | |
| # value=process_jsonl(default_json), | |
| type="pandas", | |
| visible=True, | |
| interactive=False | |
| ) | |
| upload_button.upload( | |
| fn=process_jsonl, | |
| inputs=upload_button, | |
| outputs=table, | |
| api_name="upload_jsonl" | |
| ) | |
| dff = df[0] if df else df_test | |
| r = gr.TextArea(label="review", type='text', show_label=True, value=dff.review) | |
| d = gr.Textbox(label="domain", type='text', show_label=True, value=dff.domain) | |
| with gr.Row(): | |
| true_btn = gr.Button("True") | |
| false_btn = gr.Button("False") | |
| l = gr.Textbox(label="label") | |
| def ann(num1, num2): | |
| return num1 + num2 | |
| true_btn.click(ann, inputs=[r, d], outputs=l) | |
| false_btn.click(ann, inputs=[r, d], outputs=l) | |
| # def sub(data): | |
| # return data[r] - data[d] | |
| # false_btn.click(sub, inputs={r, d}, outputs=l) | |
| # def annotate_label(df: pd.DataFrame, column: str = 'label') -> int: | |
| # df[column] = inputt | |
| # return df[column] | |
| # | |
| # iface = gr.Interface( | |
| # fn=annotate_label, # the function to call | |
| # inputs=[gr.inputs.Dataframe(headers=df.columns.tolist(), datatype=df.dtypes.tolist()), gr.inputs.Textbox()], | |
| # # the inputs | |
| # outputs="number" # the output type | |
| # ) | |
| demo.launch(debug=True) |