LennardZuendorf commited on
Commit
f5b7609
1 Parent(s): 9af39a4

adding documentation

Browse files
Files changed (1) hide show
  1. app.py +8 -0
app.py CHANGED
@@ -1,21 +1,27 @@
 
1
  import gradio as gr
2
  from transformers import pipeline
3
 
 
4
  classifier_pipe = pipeline("text-classification", model="LennardZuendorf/legalis-BERT", top_k=None)
5
 
6
 
 
7
  def predict_fun(text):
8
  predictions = classifier_pipe(text)
9
  return {p["label"]: p["score"] for p in predictions[0]}
10
 
11
 
 
12
  with gr.Blocks(title='Legalis') as interface:
 
13
  with gr.Row():
14
  gr.Markdown(
15
  """
16
  # Legalis BERT Demo
17
  Start typing below to see the output.
18
  """)
 
19
  with gr.Row():
20
  with gr.Column():
21
  input_text = gr.Textbox(label="Case Facts")
@@ -26,6 +32,8 @@ with gr.Blocks(title='Legalis') as interface:
26
  with gr.Row():
27
  interpretation = gr.components.Interpretation(input_text, visible=False)
28
 
 
29
  predict.click(predict_fun, input_text, label)
30
 
 
31
  interface.launch()
 
1
+ # imports
2
  import gradio as gr
3
  from transformers import pipeline
4
 
5
+ # load model via inference pipeline
6
  classifier_pipe = pipeline("text-classification", model="LennardZuendorf/legalis-BERT", top_k=None)
7
 
8
 
9
+ # function to predict the case winner via the model
10
  def predict_fun(text):
11
  predictions = classifier_pipe(text)
12
  return {p["label"]: p["score"] for p in predictions[0]}
13
 
14
 
15
+ # gradio interface as a block setup
16
  with gr.Blocks(title='Legalis') as interface:
17
+ # top row
18
  with gr.Row():
19
  gr.Markdown(
20
  """
21
  # Legalis BERT Demo
22
  Start typing below to see the output.
23
  """)
24
+ # middle row with input text, predict button and output label
25
  with gr.Row():
26
  with gr.Column():
27
  input_text = gr.Textbox(label="Case Facts")
 
32
  with gr.Row():
33
  interpretation = gr.components.Interpretation(input_text, visible=False)
34
 
35
+ # link predict button to predict function
36
  predict.click(predict_fun, input_text, label)
37
 
38
+ # launch command
39
  interface.launch()