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

better output

Browse files
Files changed (1) hide show
  1. app.py +16 -5
app.py CHANGED
@@ -1,24 +1,35 @@
1
  import gradio as gr
2
  from transformers import pipeline
3
 
4
- print('starat')
5
  nlp_qa = pipeline(
6
  'question-answering',
7
  model='mrm8488/bert-italian-finedtuned-squadv1-it-alfa',
8
  tokenizer='mrm8488/bert-italian-finedtuned-squadv1-it-alfa'
9
  )
10
- print('end')
 
 
 
 
 
11
 
12
  def start(question, context):
13
  response = nlp_qa({
14
  'question': question,
15
  'context': context
16
  })
17
- return response['answer'], response['score']
18
 
19
  face = gr.Interface(
20
  fn=start,
21
- inputs=[gr.inputs.Textbox(lines=1, placeholder="Question Here… "), gr.inputs.Textbox(lines=10, placeholder="Context Here… ")],
22
- outputs=["text", "number"]
 
 
 
 
 
 
 
23
  )
24
  face.launch(share=True)
 
1
  import gradio as gr
2
  from transformers import pipeline
3
 
 
4
  nlp_qa = pipeline(
5
  'question-answering',
6
  model='mrm8488/bert-italian-finedtuned-squadv1-it-alfa',
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,
25
+ inputs=[
26
+ gr.inputs.Textbox(lines=1, placeholder="Question Here… "),
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
+ ]
34
  )
35
  face.launch(share=True)