Spaces:
Running
Running
paper_version
Browse filesremove chuncks
add judge selection
more description
app.py
CHANGED
|
@@ -11,74 +11,89 @@ for index, row in df[df.category == "per_curiam"].iterrows():
|
|
| 11 |
if len(row["text"]) > 1000:
|
| 12 |
choices.append((f"""{row["case_name"]}""", [row["text"], row["year_filed"]]))
|
| 13 |
|
| 14 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 15 |
|
| 16 |
|
| 17 |
# https://www.gradio.app/guides/controlling-layout
|
| 18 |
-
def greet(opinion,
|
| 19 |
-
judges_l = (
|
| 20 |
-
df[(df["year_filed"] == year) & (df["category"] != "per_curiam")]
|
| 21 |
-
.author_name.unique()
|
| 22 |
-
.tolist()
|
| 23 |
-
)
|
| 24 |
-
|
| 25 |
-
if year == 1994:
|
| 26 |
-
judges_l.extend(["Justice Breyer", "Justice Kennedy"])
|
| 27 |
-
|
| 28 |
chunks = chunk_data(remove_citations(opinion))["text"].to_list()
|
| 29 |
result = average_text(chunks, pipe, judges_l)
|
| 30 |
-
|
| 31 |
-
|
| 32 |
-
wrt_boxes = []
|
| 33 |
-
for i in range(k):
|
| 34 |
-
wrt_boxes.append(gr.Textbox(chunks[i], visible=True))
|
| 35 |
-
wrt_boxes.append(gr.Label(value=result[1][i], visible=True))
|
| 36 |
-
return (
|
| 37 |
-
[result[0]]
|
| 38 |
-
+ wrt_boxes
|
| 39 |
-
+ [gr.Textbox(visible=False), gr.Label(visible=False)] * (max_textboxes - k)
|
| 40 |
-
)
|
| 41 |
|
| 42 |
|
| 43 |
def set_input(drop):
|
| 44 |
-
return drop[0], drop[1], gr.Slider(visible=
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 45 |
|
| 46 |
|
| 47 |
with gr.Blocks() as demo:
|
| 48 |
with gr.Row():
|
| 49 |
with gr.Column():
|
| 50 |
-
|
| 51 |
-
|
| 52 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 53 |
with gr.Row():
|
| 54 |
clear_btn = gr.Button("Clear")
|
| 55 |
greet_btn = gr.Button("Predict")
|
| 56 |
-
|
| 57 |
-
|
| 58 |
-
textboxes = []
|
| 59 |
-
for i in range(max_textboxes):
|
| 60 |
-
with gr.Row():
|
| 61 |
-
t = gr.Textbox(f"Textbox {i}", visible=False, label=f"Paragraph {i+1} Text")
|
| 62 |
-
par_level = gr.Label(
|
| 63 |
-
num_top_classes=5, label=f"Paragraph {i+1} Prediction", visible=False
|
| 64 |
)
|
| 65 |
-
textboxes.append(t)
|
| 66 |
-
textboxes.append(par_level)
|
| 67 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 68 |
drop.select(set_input, inputs=drop, outputs=[opinion, year, year])
|
| 69 |
|
| 70 |
greet_btn.click(
|
| 71 |
fn=greet,
|
| 72 |
-
inputs=[opinion,
|
| 73 |
-
outputs=[op_level]
|
| 74 |
)
|
| 75 |
|
| 76 |
clear_btn.click(
|
| 77 |
-
fn=lambda: [None, 1994, gr.Slider(visible=True), None, None]
|
| 78 |
-
|
| 79 |
-
outputs=[opinion, year, year, drop, op_level] + textboxes,
|
| 80 |
)
|
| 81 |
|
| 82 |
|
| 83 |
if __name__ == "__main__":
|
| 84 |
-
demo.launch()
|
|
|
|
| 11 |
if len(row["text"]) > 1000:
|
| 12 |
choices.append((f"""{row["case_name"]}""", [row["text"], row["year_filed"]]))
|
| 13 |
|
| 14 |
+
unique_judges_by_year = (
|
| 15 |
+
df[df.author_name != "per_curiam"].groupby("year_filed")["author_name"].unique()
|
| 16 |
+
)
|
| 17 |
+
additional_judges = ["Justice Breyer", "Justice Kennedy"]
|
| 18 |
+
unique_judges_by_year[1994] = list(unique_judges_by_year[1994]) + additional_judges
|
| 19 |
|
| 20 |
|
| 21 |
# https://www.gradio.app/guides/controlling-layout
|
| 22 |
+
def greet(opinion, judges_l):
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 23 |
chunks = chunk_data(remove_citations(opinion))["text"].to_list()
|
| 24 |
result = average_text(chunks, pipe, judges_l)
|
| 25 |
+
|
| 26 |
+
return result[0]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 27 |
|
| 28 |
|
| 29 |
def set_input(drop):
|
| 30 |
+
return drop[0], drop[1], gr.Slider(visible=True)
|
| 31 |
+
|
| 32 |
+
|
| 33 |
+
def update_year(year):
|
| 34 |
+
return gr.CheckboxGroup(
|
| 35 |
+
unique_judges_by_year[year].tolist(),
|
| 36 |
+
value=unique_judges_by_year[year].tolist(),
|
| 37 |
+
label="Select Judges",
|
| 38 |
+
)
|
| 39 |
|
| 40 |
|
| 41 |
with gr.Blocks() as demo:
|
| 42 |
with gr.Row():
|
| 43 |
with gr.Column():
|
| 44 |
+
drop = gr.Dropdown(
|
| 45 |
+
choices=sorted(choices),
|
| 46 |
+
label="Per Curiam Opinions",
|
| 47 |
+
info="Select a per curiam opinion to use as input",
|
| 48 |
+
)
|
| 49 |
+
year = gr.Slider(
|
| 50 |
+
1994,
|
| 51 |
+
2020,
|
| 52 |
+
step=1,
|
| 53 |
+
label="Year",
|
| 54 |
+
info="Select the year of the opinion if you manually pass the opinion below",
|
| 55 |
+
)
|
| 56 |
+
exc_judg = gr.CheckboxGroup(
|
| 57 |
+
unique_judges_by_year[year.value],
|
| 58 |
+
value=unique_judges_by_year[year.value],
|
| 59 |
+
label="Select Judges",
|
| 60 |
+
info="Select judges to consider in prediction",
|
| 61 |
+
)
|
| 62 |
+
|
| 63 |
+
opinion = gr.Textbox(
|
| 64 |
+
label="Opinion", info="Paste opinion text here or select from dropdown"
|
| 65 |
+
)
|
| 66 |
+
with gr.Column():
|
| 67 |
with gr.Row():
|
| 68 |
clear_btn = gr.Button("Clear")
|
| 69 |
greet_btn = gr.Button("Predict")
|
| 70 |
+
op_level = gr.outputs.Label(
|
| 71 |
+
num_top_classes=9, label="Predicted author of opinion"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 72 |
)
|
|
|
|
|
|
|
| 73 |
|
| 74 |
+
year.release(
|
| 75 |
+
update_year,
|
| 76 |
+
inputs=[year],
|
| 77 |
+
outputs=[exc_judg],
|
| 78 |
+
)
|
| 79 |
+
year.change(
|
| 80 |
+
update_year,
|
| 81 |
+
inputs=[year],
|
| 82 |
+
outputs=[exc_judg],
|
| 83 |
+
)
|
| 84 |
drop.select(set_input, inputs=drop, outputs=[opinion, year, year])
|
| 85 |
|
| 86 |
greet_btn.click(
|
| 87 |
fn=greet,
|
| 88 |
+
inputs=[opinion, exc_judg],
|
| 89 |
+
outputs=[op_level],
|
| 90 |
)
|
| 91 |
|
| 92 |
clear_btn.click(
|
| 93 |
+
fn=lambda: [None, 1994, gr.Slider(visible=True), None, None],
|
| 94 |
+
outputs=[opinion, year, year, drop, op_level],
|
|
|
|
| 95 |
)
|
| 96 |
|
| 97 |
|
| 98 |
if __name__ == "__main__":
|
| 99 |
+
demo.launch(debug=True)
|