Spaces:
Sleeping
Sleeping
Update data_labelling.py
Browse files- data_labelling.py +7 -52
data_labelling.py
CHANGED
@@ -1,56 +1,11 @@
|
|
1 |
-
import gradio as gr
|
2 |
import pandas as pd
|
3 |
-
from data_labelling import main as label_data
|
4 |
|
5 |
-
def
|
6 |
-
|
7 |
-
|
8 |
|
9 |
-
|
10 |
-
|
11 |
-
|
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 |
-
|
54 |
-
|
55 |
-
if __name__ == "__main__":
|
56 |
-
main_interface()
|
|
|
|
|
1 |
import pandas as pd
|
|
|
2 |
|
3 |
+
def label_dataset(data, columns_to_label, new_column_names):
|
4 |
+
# Dummy labeling logic for demonstration
|
5 |
+
labeled_data = data.copy()
|
6 |
|
7 |
+
for col, new_col in zip(columns_to_label, new_column_names):
|
8 |
+
# Replace this with your actual labeling logic
|
9 |
+
labeled_data[new_col] = labeled_data[col].apply(lambda x: f"Labeled-{x}")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
10 |
|
11 |
+
return labeled_data
|
|
|
|
|
|