Spaces:
Runtime error
Runtime error
File size: 2,990 Bytes
f80cc50 8ddc567 72f0cff 71645c3 72f0cff f80cc50 71645c3 926ab2a f80cc50 9c55aba f80cc50 8ddc567 9c55aba 8ddc567 fb7fb6c 9c55aba 8ddc567 f80cc50 71645c3 9c55aba 71645c3 f80cc50 fb7fb6c 9c55aba 926ab2a 9c55aba fb7fb6c 8ddc567 9c55aba 926ab2a 71645c3 8ddc567 9c55aba 8ddc567 926ab2a 9c55aba 926ab2a f80cc50 9c55aba |
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 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 |
import gradio as gr
from transformers import pipeline
from utils import *
from datasets import load_dataset
pipe = pipeline(model="raminass/scotus-v10", top_k=13, padding=True, truncation=True)
all = load_dataset("raminass/full_opinions_1994_2020")
df = pd.DataFrame(all["train"])
choices = []
for index, row in df[df.category == "per_curiam"].iterrows():
if len(row["text"]) > 1000:
choices.append((f"""{row["case_name"]}""", [row["text"], row["year_filed"]]))
unique_judges_by_year = (
df[df.author_name != "per_curiam"].groupby("year_filed")["author_name"].unique()
)
additional_judges = ["Justice Breyer", "Justice Kennedy"]
unique_judges_by_year[1994] = list(unique_judges_by_year[1994]) + additional_judges
# https://www.gradio.app/guides/controlling-layout
def greet(opinion, judges_l):
chunks = chunk_data(remove_citations(opinion))["text"].to_list()
result = average_text(chunks, pipe, judges_l)
return result[0]
def set_input(drop):
return drop[0], drop[1], gr.Slider(visible=True)
def update_year(year):
return gr.CheckboxGroup(
unique_judges_by_year[year].tolist(),
value=unique_judges_by_year[year].tolist(),
label="Select Judges",
)
with gr.Blocks() as demo:
with gr.Row():
with gr.Column():
drop = gr.Dropdown(
choices=sorted(choices),
label="Per Curiam Opinions",
info="Select a per curiam opinion to use as input",
)
year = gr.Slider(
1994,
2020,
step=1,
label="Year",
info="Select the year of the opinion if you manually pass the opinion below",
)
exc_judg = gr.CheckboxGroup(
unique_judges_by_year[year.value],
value=unique_judges_by_year[year.value],
label="Select Judges",
info="Select judges to consider in prediction",
)
opinion = gr.Textbox(
label="Opinion", info="Paste opinion text here or select from dropdown"
)
with gr.Column():
with gr.Row():
clear_btn = gr.Button("Clear")
greet_btn = gr.Button("Predict")
op_level = gr.outputs.Label(
num_top_classes=9, label="Predicted author of opinion"
)
year.release(
update_year,
inputs=[year],
outputs=[exc_judg],
)
year.change(
update_year,
inputs=[year],
outputs=[exc_judg],
)
drop.select(set_input, inputs=drop, outputs=[opinion, year, year])
greet_btn.click(
fn=greet,
inputs=[opinion, exc_judg],
outputs=[op_level],
)
clear_btn.click(
fn=lambda: [None, 1994, gr.Slider(visible=True), None, None],
outputs=[opinion, year, year, drop, op_level],
)
if __name__ == "__main__":
demo.launch(debug=True)
|