Spaces:
Runtime error
Runtime error
Commit ·
a5f80bf
1
Parent(s): e52acb8
Updated to include a tone suggestion
Browse files
app.py
CHANGED
|
@@ -12,16 +12,19 @@ def load_csv(file):
|
|
| 12 |
global current_row
|
| 13 |
# import the csv and set the data types to be int, string, string, string, string, string, string
|
| 14 |
df = pd.read_csv(file.name, dtype={'id':int, 'hs': str, 'cs': str, 'topic': str, 'tone': str, 'isCSContextuallyRelevant': str, 'isToneMatch': str})
|
|
|
|
|
|
|
| 15 |
current_row = 0
|
| 16 |
row_dict = df.iloc[current_row].to_dict()
|
| 17 |
-
return row_dict['id'], row_dict['hs'], row_dict['cs'], row_dict['topic'], row_dict['tone'], row_dict['isCSContextuallyRelevant'], row_dict['isToneMatch']
|
| 18 |
|
| 19 |
-
def annotate_row(isCSContextuallyRelevant, isToneMatch):
|
| 20 |
global df
|
| 21 |
global current_row
|
| 22 |
|
| 23 |
df.at[current_row, 'isCSContextuallyRelevant'] = isCSContextuallyRelevant
|
| 24 |
df.at[current_row, 'isToneMatch'] = isToneMatch
|
|
|
|
| 25 |
|
| 26 |
if current_row < len(df) - 1:
|
| 27 |
current_row += 1
|
|
@@ -30,7 +33,7 @@ def annotate_row(isCSContextuallyRelevant, isToneMatch):
|
|
| 30 |
df.to_csv('annotated_data.csv', index=False)
|
| 31 |
|
| 32 |
row_dict = df.iloc[current_row].to_dict()
|
| 33 |
-
return row_dict['id'], row_dict['hs'], row_dict['cs'], row_dict['topic'], row_dict['tone'], row_dict['isCSContextuallyRelevant'], row_dict['isToneMatch'], 'annotated_data.csv'
|
| 34 |
|
| 35 |
def navigate(direction):
|
| 36 |
global current_row
|
|
@@ -44,7 +47,7 @@ def navigate(direction):
|
|
| 44 |
current_row = int(unlabeled_row)
|
| 45 |
|
| 46 |
row_dict = df.iloc[current_row].to_dict()
|
| 47 |
-
return row_dict['id'], row_dict['hs'], row_dict['cs'], row_dict['topic'], row_dict['tone'], row_dict['isCSContextuallyRelevant'], row_dict['isToneMatch']
|
| 48 |
|
| 49 |
with gr.Blocks(theme=gr.themes.Soft()) as annotator:
|
| 50 |
gr.Markdown("## Data Annotation")
|
|
@@ -68,6 +71,7 @@ with gr.Blocks(theme=gr.themes.Soft()) as annotator:
|
|
| 68 |
with gr.Row():
|
| 69 |
isCSContextuallyRelevant = gr.Radio(["1", "0"], label="Contextually Relevant?")
|
| 70 |
isToneMatch = gr.Radio(["1", "0"], label="Tone Match?")
|
|
|
|
| 71 |
btn_annotate = gr.Button("Annotate")
|
| 72 |
|
| 73 |
with gr.Row():
|
|
@@ -79,10 +83,10 @@ with gr.Blocks(theme=gr.themes.Soft()) as annotator:
|
|
| 79 |
gr.Markdown("### Annotated Data File Download")
|
| 80 |
file_download = gr.File()
|
| 81 |
|
| 82 |
-
btn_load.click(load_csv, inputs=[file_upload], outputs=[idx, hs, cs, topic, tone, isCSContextuallyRelevant, isToneMatch])
|
| 83 |
-
btn_annotate.click(annotate_row, inputs=[isCSContextuallyRelevant, isToneMatch], outputs=[idx, hs, cs, topic, tone, isCSContextuallyRelevant, isToneMatch, file_download])
|
| 84 |
-
btn_previous.click(navigate, inputs=gr.Textbox("Previous", visible=False), outputs=[idx, hs, cs, topic, tone, isCSContextuallyRelevant, isToneMatch])
|
| 85 |
-
btn_next.click(navigate, inputs=gr.Textbox("Next", visible=False), outputs=[idx, hs, cs, topic, tone, isCSContextuallyRelevant, isToneMatch])
|
| 86 |
-
btn_first_unlabeled.click(navigate, inputs=gr.Textbox("First Unlabeled", visible=False), outputs=[idx, hs, cs, topic, tone, isCSContextuallyRelevant, isToneMatch])
|
| 87 |
|
| 88 |
annotator.launch()
|
|
|
|
| 12 |
global current_row
|
| 13 |
# import the csv and set the data types to be int, string, string, string, string, string, string
|
| 14 |
df = pd.read_csv(file.name, dtype={'id':int, 'hs': str, 'cs': str, 'topic': str, 'tone': str, 'isCSContextuallyRelevant': str, 'isToneMatch': str})
|
| 15 |
+
if 'suggestedTone' not in df.columns:
|
| 16 |
+
df['suggestedTone'] = None
|
| 17 |
current_row = 0
|
| 18 |
row_dict = df.iloc[current_row].to_dict()
|
| 19 |
+
return row_dict['id'], row_dict['hs'], row_dict['cs'], row_dict['topic'], row_dict['tone'], row_dict['isCSContextuallyRelevant'], row_dict['isToneMatch'], row_dict['suggestedTone']
|
| 20 |
|
| 21 |
+
def annotate_row(isCSContextuallyRelevant, isToneMatch, suggestedTone):
|
| 22 |
global df
|
| 23 |
global current_row
|
| 24 |
|
| 25 |
df.at[current_row, 'isCSContextuallyRelevant'] = isCSContextuallyRelevant
|
| 26 |
df.at[current_row, 'isToneMatch'] = isToneMatch
|
| 27 |
+
df.at[current_row, 'suggestedTone'] = suggestedTone
|
| 28 |
|
| 29 |
if current_row < len(df) - 1:
|
| 30 |
current_row += 1
|
|
|
|
| 33 |
df.to_csv('annotated_data.csv', index=False)
|
| 34 |
|
| 35 |
row_dict = df.iloc[current_row].to_dict()
|
| 36 |
+
return row_dict['id'], row_dict['hs'], row_dict['cs'], row_dict['topic'], row_dict['tone'], row_dict['isCSContextuallyRelevant'], row_dict['isToneMatch'], row_dict['suggestedTone'], 'annotated_data.csv'
|
| 37 |
|
| 38 |
def navigate(direction):
|
| 39 |
global current_row
|
|
|
|
| 47 |
current_row = int(unlabeled_row)
|
| 48 |
|
| 49 |
row_dict = df.iloc[current_row].to_dict()
|
| 50 |
+
return row_dict['id'], row_dict['hs'], row_dict['cs'], row_dict['topic'], row_dict['tone'], row_dict['isCSContextuallyRelevant'], row_dict['isToneMatch'], row_dict['suggestedTone']
|
| 51 |
|
| 52 |
with gr.Blocks(theme=gr.themes.Soft()) as annotator:
|
| 53 |
gr.Markdown("## Data Annotation")
|
|
|
|
| 71 |
with gr.Row():
|
| 72 |
isCSContextuallyRelevant = gr.Radio(["1", "0"], label="Contextually Relevant?")
|
| 73 |
isToneMatch = gr.Radio(["1", "0"], label="Tone Match?")
|
| 74 |
+
suggestedTone = gr.Textbox(label='Suggested Tone', interactive=True)
|
| 75 |
btn_annotate = gr.Button("Annotate")
|
| 76 |
|
| 77 |
with gr.Row():
|
|
|
|
| 83 |
gr.Markdown("### Annotated Data File Download")
|
| 84 |
file_download = gr.File()
|
| 85 |
|
| 86 |
+
btn_load.click(load_csv, inputs=[file_upload], outputs=[idx, hs, cs, topic, tone, isCSContextuallyRelevant, isToneMatch, suggestedTone])
|
| 87 |
+
btn_annotate.click(annotate_row, inputs=[isCSContextuallyRelevant, isToneMatch, suggestedTone], outputs=[idx, hs, cs, topic, tone, isCSContextuallyRelevant, isToneMatch, suggestedTone, file_download])
|
| 88 |
+
btn_previous.click(navigate, inputs=gr.Textbox("Previous", visible=False), outputs=[idx, hs, cs, topic, tone, isCSContextuallyRelevant, isToneMatch, suggestedTone])
|
| 89 |
+
btn_next.click(navigate, inputs=gr.Textbox("Next", visible=False), outputs=[idx, hs, cs, topic, tone, isCSContextuallyRelevant, isToneMatch, suggestedTone])
|
| 90 |
+
btn_first_unlabeled.click(navigate, inputs=gr.Textbox("First Unlabeled", visible=False), outputs=[idx, hs, cs, topic, tone, isCSContextuallyRelevant, isToneMatch, suggestedTone])
|
| 91 |
|
| 92 |
annotator.launch()
|