raminass commited on
Commit
f80cc50
·
1 Parent(s): c5e421f

create app.py

Browse files
Files changed (1) hide show
  1. app.py +34 -0
app.py ADDED
@@ -0,0 +1,34 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ from transformers import pipeline, TextClassificationPipeline
3
+ pipe = pipeline(model="raminass/scotus-v10", top_k=13, padding=True, truncation=True)
4
+
5
+ def average_text(text, model):
6
+ # result = classifier(df_train[(df_train.case_name==case) & (df_train.category=='per_curiam')]['clean_text'].to_list())
7
+ result = model(text)
8
+ pred = {}
9
+ for c in result:
10
+ for d in c:
11
+ if d['label'] not in pred:
12
+ pred[d['label']] = [round(d['score'],2)]
13
+ else:
14
+ pred[d['label']].append(round(d['score'],2))
15
+ sumary = {k:round(sum(v)/len(v),2) for k,v in pred.items()}
16
+ result = [[{k: round(v, 2) if k=='score' else v for k, v in dct.items()} for dct in lst ] for lst in result]
17
+ return dict(sorted(sumary.items(), key=lambda x: x[1],reverse=True)), result
18
+
19
+ def greet(opinion):
20
+ result = average_text(chunk_data(remove_citations(opinion))['text'].to_list(),pipe)
21
+ # print(f"average prediction:")
22
+ # display(result[0])
23
+ # print(f"paragraph prediction:")
24
+ # display(result[1])
25
+ return result[0]
26
+
27
+ with gr.Blocks() as demo:
28
+ opinion = gr.Textbox(label="Opinion")
29
+ output = gr.Textbox(label="Result")
30
+ greet_btn = gr.Button("Predict")
31
+ greet_btn.click(fn=greet, inputs=opinion, outputs=output, api_name="SCOTUS")
32
+
33
+ if __name__ == "__main__":
34
+ demo.launch()