File size: 2,071 Bytes
5284cc6
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
import gradio as gr
import pandas as pd
from data_labelling import main as label_data

def preview_data(file):
    if file is None:
        return "Please upload a CSV file."
    
    df = pd.read_csv(file.name)
    preview = df.head()  # Show the first few lines of the dataset
    return gr.DataFrame(preview), df.shape  # Return the preview and the shape of the dataset

def run_labeling(input_file, output_file):
    # Run the labeling script
    labeled_file = label_data(input_file, output_file)
    return labeled_file  # Return the path to the labeled file

def main_interface():
    with gr.Blocks() as demo:
        gr.Markdown("# YouTube Comments Labeling")
        
        with gr.Row():
            file_input = gr.File(label="Upload your CSV file")
            preview_button = gr.Button("Preview Data")
        
        data_preview = gr.DataFrame()
        data_shape = gr.Textbox(label="Dataset Shape", interactive=False)
        
        preview_button.click(preview_data, inputs=file_input, outputs=[data_preview, data_shape])
        
        with gr.Row():
            label_option = gr.Radio(["No", "Yes"], label="Do you want to label your dataset?", value="No")
        
        output_name = gr.Textbox(label="Output File Name (with .csv extension)", value="labeled_dataset.csv")
        label_button = gr.Button("Run Labeling")
        
        labeled_file_path = gr.Textbox(label="Labeled File Path", interactive=False)
        download_button = gr.File(label="Download Labeled File")
        
        def handle_labeling(input_file, label_choice, output_name):
            if label_choice == "Yes":
                labeled_file = run_labeling(input_file.name, output_name)
                return labeled_file, labeled_file
            else:
                return None, None
        
        label_button.click(
            handle_labeling, 
            inputs=[file_input, label_option, output_name], 
            outputs=[labeled_file_path, download_button]
        )
    
    demo.launch()

if __name__ == "__main__":
    main_interface()