z-uo commited on
Commit
de1d8fb
1 Parent(s): 89c1253

Visualization automatic Highlight

Browse files
Files changed (1) hide show
  1. app.py +8 -8
app.py CHANGED
@@ -7,18 +7,18 @@ nlp_qa = pipeline(
7
  tokenizer='mrm8488/bert-italian-finedtuned-squadv1-it-alfa'
8
  )
9
 
10
- def get_colored_text(response, context):
11
- colored_string = context[:response['start']] + \
12
- '<span style="color:blue">' + context[response['start']:response['end']] + '</span>' + \
13
- context[response['end']:]
14
- return colored_string
15
-
16
  def start(question, context):
17
  response = nlp_qa({
18
  'question': question,
19
  'context': context
20
  })
21
- return get_colored_text(response, context), response['answer'], {response['answer']: response['score']}
 
 
 
 
 
 
22
 
23
  face = gr.Interface(
24
  fn=start,
@@ -27,7 +27,7 @@ face = gr.Interface(
27
  gr.inputs.Textbox(lines=10, placeholder="Context Here… ")
28
  ],
29
  outputs=[
30
- gr.outputs.HTML(label='Context'),
31
  gr.outputs.Textbox(label="Answer"),
32
  gr.outputs.Label(num_top_classes=1, label='Score'),
33
  ]
 
7
  tokenizer='mrm8488/bert-italian-finedtuned-squadv1-it-alfa'
8
  )
9
 
 
 
 
 
 
 
10
  def start(question, context):
11
  response = nlp_qa({
12
  'question': question,
13
  'context': context
14
  })
15
+ text_hilight_output = [
16
+ (context[:response['start']], None),
17
+ (context[response['start']:response['end']], 'Answer'),
18
+ (context[response['end']:], None)
19
+
20
+ ]
21
+ return text_hilight_output, response['answer'], {response['answer']: response['score']}
22
 
23
  face = gr.Interface(
24
  fn=start,
 
27
  gr.inputs.Textbox(lines=10, placeholder="Context Here… ")
28
  ],
29
  outputs=[
30
+ gr.outputs.HighlightedText(label='Context'),
31
  gr.outputs.Textbox(label="Answer"),
32
  gr.outputs.Label(num_top_classes=1, label='Score'),
33
  ]