khadija3818 commited on
Commit
3208af3
·
1 Parent(s): 5ec58bc

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +21 -22
app.py CHANGED
@@ -2,44 +2,43 @@ from deepsparse import Pipeline
2
  import time
3
  import gradio as gr
4
 
5
-
6
  task = "zero_shot_text_classification"
7
  sparse_classification_pipeline = Pipeline.create(
8
- task=task,
9
- model_path="zoo:nlp/text_classification/distilbert-none/pytorch/huggingface/mnli/pruned80_quant-none-vnni",
10
- model_scheme="mnli",
11
  model_config={"hypothesis_template": "This text is related to {}"},
12
- )
 
13
  def run_pipeline(text):
14
  sparse_start = time.perf_counter()
15
- sparse_output = sparse_classification_pipeline(sequences= text,labels=['politics', 'public health', 'Europe'],)
16
  sparse_result = dict(sparse_output)
17
  sparse_end = time.perf_counter()
18
  sparse_duration = (sparse_end - sparse_start) * 1000.0
19
- dict_r = {sparse_result['labels'][0]:sparse_result['scores'][0],sparse_result['labels'][1]:sparse_result['scores'][1], sparse_result['labels'][2]:sparse_result['scores'][2]}
 
 
 
 
20
  return dict_r, sparse_duration
21
 
22
-
23
  with gr.Blocks() as demo:
24
  with gr.Row():
25
  with gr.Column():
26
- gr.Markdown(markdownn)
27
-
28
- )
29
- text = gr.Text(label="Text")
30
- btn = gr.Button("Submit")
31
-
32
- sparse_answers = gr.Label(label="Sparse model answers",
33
- num_top_classes=3
34
- )
35
- sparse_duration = gr.Number(label="Sparse Latency (ms):")
36
- gr.Examples([["The senate passed 3 laws today"],["Who are you voting for in 2020?"],["Public health is very important"]],inputs=[text],)
37
-
38
  btn.click(
39
  run_pipeline,
40
  inputs=[text],
41
- outputs=[sparse_answers,sparse_duration],
42
  )
43
 
44
  if __name__ == "__main__":
45
- demo.launch()
 
2
  import time
3
  import gradio as gr
4
 
 
5
  task = "zero_shot_text_classification"
6
  sparse_classification_pipeline = Pipeline.create(
7
+ task=task,
8
+ model_path="zoo:nlp/text_classification/distilbert-none/pytorch/huggingface/mnli/pruned80_quant-none-vnni",
9
+ model_scheme="mnli",
10
  model_config={"hypothesis_template": "This text is related to {}"},
11
+ )
12
+
13
  def run_pipeline(text):
14
  sparse_start = time.perf_counter()
15
+ sparse_output = sparse_classification_pipeline(sequences=text, labels=['politics', 'public health', 'Europe'])
16
  sparse_result = dict(sparse_output)
17
  sparse_end = time.perf_counter()
18
  sparse_duration = (sparse_end - sparse_start) * 1000.0
19
+ dict_r = {
20
+ sparse_result['labels'][0]: sparse_result['scores'][0],
21
+ sparse_result['labels'][1]: sparse_result['scores'][1],
22
+ sparse_result['labels'][2]: sparse_result['scores'][2]
23
+ }
24
  return dict_r, sparse_duration
25
 
 
26
  with gr.Blocks() as demo:
27
  with gr.Row():
28
  with gr.Column():
29
+ text = gr.Textbox(placeholder="Enter text here...", label="Text", lines=5, width=500)
30
+ btn = gr.Button("Submit", style="info", size="lg", block=True)
31
+
32
+ with gr.Column():
33
+ gr.Markdown("### Text Classification Demo")
34
+ sparse_answers = gr.Label(label="Sparse Model Answers", num_top_classes=3, style="info")
35
+ sparse_duration = gr.Number(label="Sparse Latency (ms)", style="success", size="lg")
36
+
 
 
 
 
37
  btn.click(
38
  run_pipeline,
39
  inputs=[text],
40
+ outputs=[sparse_answers, sparse_duration],
41
  )
42
 
43
  if __name__ == "__main__":
44
+ demo.launch()