Spaces:
Sleeping
Sleeping
Upload app.py
Browse files
app.py
CHANGED
|
@@ -1,6 +1,6 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
import os
|
| 3 |
-
from interface_utils import *
|
| 4 |
|
| 5 |
maxim = 'quantity'
|
| 6 |
submaxims = ["The response provides a sufficient amount of information.",
|
|
@@ -10,7 +10,7 @@ checkbox_choices = [
|
|
| 10 |
["Yes", "No", "NA"]
|
| 11 |
]
|
| 12 |
|
| 13 |
-
conversation_data_sliced = load_from_jsonl('
|
| 14 |
max_conversation_length = max([len(conversation['transcript']) for conversation in conversation_data_sliced])
|
| 15 |
|
| 16 |
conversation = get_conversation(conversation_data_sliced)
|
|
@@ -25,9 +25,9 @@ def save_labels(conv_id, slice_idx, skipped, submaxim_0=None, submaxim_1=None):
|
|
| 25 |
'submaxim_0': submaxim_0,
|
| 26 |
'submaxim_1': submaxim_1,
|
| 27 |
}
|
| 28 |
-
os.makedirs("
|
| 29 |
|
| 30 |
-
with open(f"
|
| 31 |
json.dump(data, f, indent=4)
|
| 32 |
|
| 33 |
|
|
@@ -39,19 +39,20 @@ def update_interface(new_conversation):
|
|
| 39 |
markdown_blocks = [None] * max_conversation_length
|
| 40 |
for i in range(max_conversation_length):
|
| 41 |
if i < len(new_transcript) and new_transcript[i]['speaker'] != '':
|
| 42 |
-
|
| 43 |
-
f""" **{new_transcript[i]['speaker']}**: {new_transcript[i]['response']}""",
|
| 44 |
-
|
|
|
|
| 45 |
else:
|
| 46 |
markdown_blocks[i] = gr.Markdown("", visible=False)
|
| 47 |
|
| 48 |
-
new_last_response = gr.Text(value=get_last_response(new_transcript),
|
| 49 |
-
|
| 50 |
-
|
| 51 |
-
|
| 52 |
-
|
| 53 |
-
|
| 54 |
-
|
| 55 |
new_radio_0_base = gr.Radio(label=submaxims[0],
|
| 56 |
choices=checkbox_choices[0],
|
| 57 |
value=None,
|
|
@@ -62,7 +63,7 @@ def update_interface(new_conversation):
|
|
| 62 |
visible=True)
|
| 63 |
conv_len = gr.Number(value=len(new_transcript), visible=False)
|
| 64 |
|
| 65 |
-
return [new_conv_id] + [new_slice_idx] + list(markdown_blocks) + [
|
| 66 |
|
| 67 |
|
| 68 |
def submit(*args):
|
|
@@ -95,12 +96,14 @@ with gr.Blocks(theme=gr.themes.Default()) as interface:
|
|
| 95 |
markdown_blocks = [None] * max_conversation_length
|
| 96 |
with gr.Column(scale=1, min_width=600):
|
| 97 |
with gr.Group():
|
| 98 |
-
gr.Markdown("""<span style='font-size: 16px;'> **
|
| 99 |
visible=True)
|
| 100 |
for i in range(max_conversation_length):
|
| 101 |
if i < len(transcript):
|
| 102 |
-
|
| 103 |
-
f""" **{transcript[i]['speaker']}**: {transcript[i]['response']}""")
|
|
|
|
|
|
|
| 104 |
else:
|
| 105 |
markdown_blocks[i] = gr.Markdown("")
|
| 106 |
if i >= conv_len.value:
|
|
@@ -109,15 +112,15 @@ with gr.Blocks(theme=gr.themes.Default()) as interface:
|
|
| 109 |
with gr.Row():
|
| 110 |
with gr.Group(elem_classes="bottom-aligned-group"):
|
| 111 |
speaker_adapted = gr.Markdown(
|
| 112 |
-
f"""<span style='font-size: 16px;'> **
|
| 113 |
visible=True)
|
| 114 |
-
last_response = gr.Textbox(value=get_last_response(transcript),
|
| 115 |
-
|
| 116 |
-
|
| 117 |
-
|
| 118 |
-
|
| 119 |
-
|
| 120 |
-
|
| 121 |
radio_submaxim_0_base = gr.Radio(label=submaxims[0],
|
| 122 |
choices=checkbox_choices[0],
|
| 123 |
value=None,
|
|
@@ -135,7 +138,6 @@ with gr.Blocks(theme=gr.themes.Default()) as interface:
|
|
| 135 |
input_list = [conv_id_element] + \
|
| 136 |
[slice_idx_element] + \
|
| 137 |
markdown_blocks + \
|
| 138 |
-
[last_response] + \
|
| 139 |
[radio_submaxim_0_base] + \
|
| 140 |
[radio_submaxim_1_base] + \
|
| 141 |
[conv_len]
|
|
@@ -145,7 +147,6 @@ with gr.Blocks(theme=gr.themes.Default()) as interface:
|
|
| 145 |
outputs=[conv_id_element,
|
| 146 |
slice_idx_element,
|
| 147 |
*markdown_blocks,
|
| 148 |
-
last_response,
|
| 149 |
radio_submaxim_0_base,
|
| 150 |
radio_submaxim_1_base,
|
| 151 |
conv_len]
|
|
@@ -156,7 +157,6 @@ with gr.Blocks(theme=gr.themes.Default()) as interface:
|
|
| 156 |
outputs=[conv_id_element,
|
| 157 |
slice_idx_element,
|
| 158 |
*markdown_blocks,
|
| 159 |
-
last_response,
|
| 160 |
radio_submaxim_0_base,
|
| 161 |
radio_submaxim_1_base,
|
| 162 |
conv_len]
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
import os
|
| 3 |
+
from gradio_interfaces.conversation_labeling.interface_utils import *
|
| 4 |
|
| 5 |
maxim = 'quantity'
|
| 6 |
submaxims = ["The response provides a sufficient amount of information.",
|
|
|
|
| 10 |
["Yes", "No", "NA"]
|
| 11 |
]
|
| 12 |
|
| 13 |
+
conversation_data_sliced = load_from_jsonl('../../../data/unlabeled/conversations_unlabeled_sliced.jsonl')
|
| 14 |
max_conversation_length = max([len(conversation['transcript']) for conversation in conversation_data_sliced])
|
| 15 |
|
| 16 |
conversation = get_conversation(conversation_data_sliced)
|
|
|
|
| 25 |
'submaxim_0': submaxim_0,
|
| 26 |
'submaxim_1': submaxim_1,
|
| 27 |
}
|
| 28 |
+
os.makedirs("../labels", exist_ok=True)
|
| 29 |
|
| 30 |
+
with open(f"../labels/{maxim}_human_labels_{conv_id}_{slice_idx}.json", 'w') as f:
|
| 31 |
json.dump(data, f, indent=4)
|
| 32 |
|
| 33 |
|
|
|
|
| 39 |
markdown_blocks = [None] * max_conversation_length
|
| 40 |
for i in range(max_conversation_length):
|
| 41 |
if i < len(new_transcript) and new_transcript[i]['speaker'] != '':
|
| 42 |
+
if i < len(transcript) - 1:
|
| 43 |
+
markdown_blocks[i] = gr.Markdown(f""" **{new_transcript[i]['speaker']}**: {new_transcript[i]['response']}""", visible=True)
|
| 44 |
+
if i == len(transcript) - 1:
|
| 45 |
+
markdown_blocks[i] = gr.Markdown(f""" **{transcript[i]['speaker']}**: <mark style="background-color: lightyellow">{transcript[i]['response']}</mark>""", visible=True)
|
| 46 |
else:
|
| 47 |
markdown_blocks[i] = gr.Markdown("", visible=False)
|
| 48 |
|
| 49 |
+
# new_last_response = gr.Text(value=get_last_response(new_transcript),
|
| 50 |
+
# label="",
|
| 51 |
+
# lines=1,
|
| 52 |
+
# container=False,
|
| 53 |
+
# interactive=False,
|
| 54 |
+
# autoscroll=True,
|
| 55 |
+
# visible=True)
|
| 56 |
new_radio_0_base = gr.Radio(label=submaxims[0],
|
| 57 |
choices=checkbox_choices[0],
|
| 58 |
value=None,
|
|
|
|
| 63 |
visible=True)
|
| 64 |
conv_len = gr.Number(value=len(new_transcript), visible=False)
|
| 65 |
|
| 66 |
+
return [new_conv_id] + [new_slice_idx] + list(markdown_blocks) + [new_radio_0_base] + [new_radio_1_base] + [conv_len]
|
| 67 |
|
| 68 |
|
| 69 |
def submit(*args):
|
|
|
|
| 96 |
markdown_blocks = [None] * max_conversation_length
|
| 97 |
with gr.Column(scale=1, min_width=600):
|
| 98 |
with gr.Group():
|
| 99 |
+
gr.Markdown("""<span style='font-size: 16px;'> **Conversation** </span>""",
|
| 100 |
visible=True)
|
| 101 |
for i in range(max_conversation_length):
|
| 102 |
if i < len(transcript):
|
| 103 |
+
if i < len(transcript) - 1:
|
| 104 |
+
markdown_blocks[i] = gr.Markdown(f""" **{transcript[i]['speaker']}**: {transcript[i]['response']}""")
|
| 105 |
+
if i == len(transcript) - 1:
|
| 106 |
+
markdown_blocks[i] = gr.Markdown(f""" **{transcript[i]['speaker']}**: <mark style="background-color: lightyellow">{transcript[i]['response']}</mark>""")
|
| 107 |
else:
|
| 108 |
markdown_blocks[i] = gr.Markdown("")
|
| 109 |
if i >= conv_len.value:
|
|
|
|
| 112 |
with gr.Row():
|
| 113 |
with gr.Group(elem_classes="bottom-aligned-group"):
|
| 114 |
speaker_adapted = gr.Markdown(
|
| 115 |
+
f"""<span style='font-size: 16px;'> **Labels** </span>""",
|
| 116 |
visible=True)
|
| 117 |
+
# last_response = gr.Textbox(value=get_last_response(transcript),
|
| 118 |
+
# label="",
|
| 119 |
+
# lines=1,
|
| 120 |
+
# container=False,
|
| 121 |
+
# interactive=False,
|
| 122 |
+
# autoscroll=True,
|
| 123 |
+
# visible=True)
|
| 124 |
radio_submaxim_0_base = gr.Radio(label=submaxims[0],
|
| 125 |
choices=checkbox_choices[0],
|
| 126 |
value=None,
|
|
|
|
| 138 |
input_list = [conv_id_element] + \
|
| 139 |
[slice_idx_element] + \
|
| 140 |
markdown_blocks + \
|
|
|
|
| 141 |
[radio_submaxim_0_base] + \
|
| 142 |
[radio_submaxim_1_base] + \
|
| 143 |
[conv_len]
|
|
|
|
| 147 |
outputs=[conv_id_element,
|
| 148 |
slice_idx_element,
|
| 149 |
*markdown_blocks,
|
|
|
|
| 150 |
radio_submaxim_0_base,
|
| 151 |
radio_submaxim_1_base,
|
| 152 |
conv_len]
|
|
|
|
| 157 |
outputs=[conv_id_element,
|
| 158 |
slice_idx_element,
|
| 159 |
*markdown_blocks,
|
|
|
|
| 160 |
radio_submaxim_0_base,
|
| 161 |
radio_submaxim_1_base,
|
| 162 |
conv_len]
|