Abu1998 commited on
Commit
5284cc6
·
verified ·
1 Parent(s): 32712b9

Create data_labelling.py

Browse files
Files changed (1) hide show
  1. data_labelling.py +56 -0
data_labelling.py ADDED
@@ -0,0 +1,56 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ import pandas as pd
3
+ from data_labelling import main as label_data
4
+
5
+ def preview_data(file):
6
+ if file is None:
7
+ return "Please upload a CSV file."
8
+
9
+ df = pd.read_csv(file.name)
10
+ preview = df.head() # Show the first few lines of the dataset
11
+ return gr.DataFrame(preview), df.shape # Return the preview and the shape of the dataset
12
+
13
+ def run_labeling(input_file, output_file):
14
+ # Run the labeling script
15
+ labeled_file = label_data(input_file, output_file)
16
+ return labeled_file # Return the path to the labeled file
17
+
18
+ def main_interface():
19
+ with gr.Blocks() as demo:
20
+ gr.Markdown("# YouTube Comments Labeling")
21
+
22
+ with gr.Row():
23
+ file_input = gr.File(label="Upload your CSV file")
24
+ preview_button = gr.Button("Preview Data")
25
+
26
+ data_preview = gr.DataFrame()
27
+ data_shape = gr.Textbox(label="Dataset Shape", interactive=False)
28
+
29
+ preview_button.click(preview_data, inputs=file_input, outputs=[data_preview, data_shape])
30
+
31
+ with gr.Row():
32
+ label_option = gr.Radio(["No", "Yes"], label="Do you want to label your dataset?", value="No")
33
+
34
+ output_name = gr.Textbox(label="Output File Name (with .csv extension)", value="labeled_dataset.csv")
35
+ label_button = gr.Button("Run Labeling")
36
+
37
+ labeled_file_path = gr.Textbox(label="Labeled File Path", interactive=False)
38
+ download_button = gr.File(label="Download Labeled File")
39
+
40
+ def handle_labeling(input_file, label_choice, output_name):
41
+ if label_choice == "Yes":
42
+ labeled_file = run_labeling(input_file.name, output_name)
43
+ return labeled_file, labeled_file
44
+ else:
45
+ return None, None
46
+
47
+ label_button.click(
48
+ handle_labeling,
49
+ inputs=[file_input, label_option, output_name],
50
+ outputs=[labeled_file_path, download_button]
51
+ )
52
+
53
+ demo.launch()
54
+
55
+ if __name__ == "__main__":
56
+ main_interface()