File size: 1,769 Bytes
f80cc50
b27cd71
 
8ddc567
72f0cff
71645c3
8fbc997
72f0cff
f3b8201
b27cd71
71645c3
f3b8201
 
8ddc567
b27cd71
8ddc567
b27cd71
 
 
 
9c55aba
 
8ddc567
f80cc50
71645c3
9c55aba
 
 
f80cc50
fb7fb6c
eecd399
9c55aba
 
b27cd71
 
9c55aba
 
 
b27cd71
 
9c55aba
eecd399
926ab2a
 
 
b27cd71
8ddc567
b27cd71
71645c3
8ddc567
 
b27cd71
9c55aba
8ddc567
 
926ab2a
9c55aba
b27cd71
926ab2a
 
f80cc50
 
b27cd71
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
58
59
60
61
62
63
64
import gradio as gr
from gradio.components import Label, Textbox

from transformers import pipeline
from utils import *
from datasets import load_dataset
import json

pipe = pipeline(model="raminass/british", top_k=2, padding=True, truncation=True)
df = pd.read_csv("data.csv", sep="\t")
choices = []
for index, row in df.iterrows():
    choices.append((f"""{row["case"]}""", [row["text"], row["author"]]))


# https://www.gradio.app/guides/controlling-layout
def greet(opinion):
    opinion = opinion.replace("(", "").replace(")", "")
    chunks = chunk_data(opinion)["text"].to_list()
    result = average_text(chunks, pipe)

    return result[0]


def set_input(drop):
    return drop[0], drop[1], gr.Slider(visible=True)


with gr.Blocks() as demo:
    with gr.Row():
        with gr.Column(scale=2):
            drop = gr.Dropdown(
                choices=sorted(choices),
                label="List of Cases",
                info="Select a case from the dropdown menu and press the Predict Button",
            )

            opinion = gr.Textbox(
                label="Opinion",
                info="Paste opinion text here and press the Predict Button",
            )
        with gr.Column(scale=1):
            with gr.Row():
                clear_btn = gr.Button("Clear")
                greet_btn = gr.Button("Predict")
            op_level = Label(num_top_classes=9, label="Predicted author of opinion")

    drop.select(set_input, inputs=drop, outputs=[opinion])

    greet_btn.click(
        fn=greet,
        inputs=[opinion],
        outputs=[op_level],
    )

    clear_btn.click(
        fn=lambda: [None, 1994, gr.Slider(visible=True), None, None],
        outputs=[opinion, drop, op_level],
    )


if __name__ == "__main__":
    demo.launch()