Ubuntu commited on
Commit
df4c9ba
1 Parent(s): 1589ac0
Files changed (1) hide show
  1. app.py +11 -2
app.py CHANGED
@@ -1,4 +1,5 @@
1
  import gradio as gr
 
2
  from optimum.intel.openvino import OVModelForSequenceClassification
3
  from transformers import AutoModelForSequenceClassification, AutoTokenizer, pipeline
4
 
@@ -10,11 +11,18 @@ tokenizer = AutoTokenizer.from_pretrained(model_id)
10
 
11
  p = pipeline("text-classification", model=ov_model, tokenizer=tokenizer)
12
 
 
 
 
 
13
 
14
  def process(text, top_k=5):
 
15
  pred = p(text, top_k=top_k)
 
16
  scores = {x["label"]: x["score"] for x in pred}
17
- return scores
 
18
 
19
 
20
  # Gradio inputs
@@ -22,6 +30,7 @@ input_text = gr.Text(label="Enter text")
22
 
23
  # Gradio outputs
24
  labels = gr.Label(label="Languages", num_top_classes=5)
 
25
 
26
  description = "This Space lets you perform language identification on the 102 languages present in the google/fleurs dataset. The underlying model scores 99.3% accuracy on the validation set. Inference is optimized with Optimum Intel and OpenVINO."
27
 
@@ -29,7 +38,7 @@ iface = gr.Interface(
29
  description=description,
30
  fn=process,
31
  inputs=input_text,
32
- outputs=labels,
33
  examples=[
34
  "Kila mtu ana haki ya kuelimishwa. Elimu yapasa itolewe bure hasa ile ya madarasa ya chini. Elimu ya masarasa ya chini ihudhuriwe kwa lazima. Elimu ya ufundi na ustadi iwe wazi kwa wote. Na elimu ya juu iwe wazi kwa wote kwa kutegemea sifa ya mtu",
35
  "Ang bawat tao'y may karapatan sa edukasyon. Ang edukasyon ay walang bayad, doon man lamang sa elementarya at pangunahing antas. Ang edukasyong elementarya ay magiging sapilitan. Ang edukasyong teknikal at propesyonal ay gagawing maabot ng lahat at ang lalong mataas na edukasyon ay ipagkakaloob nang pantay-pantay sa lahat batay sa pagiging karapat-dapat.",
 
1
  import gradio as gr
2
+ import time
3
  from optimum.intel.openvino import OVModelForSequenceClassification
4
  from transformers import AutoModelForSequenceClassification, AutoTokenizer, pipeline
5
 
 
11
 
12
  p = pipeline("text-classification", model=ov_model, tokenizer=tokenizer)
13
 
14
+ # Warmum
15
+ for i in range(100):
16
+ p("Hello world")
17
+
18
 
19
  def process(text, top_k=5):
20
+ tick = time.time()
21
  pred = p(text, top_k=top_k)
22
+ tock = time.time()
23
  scores = {x["label"]: x["score"] for x in pred}
24
+ msg = f'Predicted in {(tock-tick).format(":2f")} milliseconds'
25
+ return scores, msg
26
 
27
 
28
  # Gradio inputs
 
30
 
31
  # Gradio outputs
32
  labels = gr.Label(label="Languages", num_top_classes=5)
33
+ output_text = gr.Text()
34
 
35
  description = "This Space lets you perform language identification on the 102 languages present in the google/fleurs dataset. The underlying model scores 99.3% accuracy on the validation set. Inference is optimized with Optimum Intel and OpenVINO."
36
 
 
38
  description=description,
39
  fn=process,
40
  inputs=input_text,
41
+ outputs=[labels, output_text],
42
  examples=[
43
  "Kila mtu ana haki ya kuelimishwa. Elimu yapasa itolewe bure hasa ile ya madarasa ya chini. Elimu ya masarasa ya chini ihudhuriwe kwa lazima. Elimu ya ufundi na ustadi iwe wazi kwa wote. Na elimu ya juu iwe wazi kwa wote kwa kutegemea sifa ya mtu",
44
  "Ang bawat tao'y may karapatan sa edukasyon. Ang edukasyon ay walang bayad, doon man lamang sa elementarya at pangunahing antas. Ang edukasyong elementarya ay magiging sapilitan. Ang edukasyong teknikal at propesyonal ay gagawing maabot ng lahat at ang lalong mataas na edukasyon ay ipagkakaloob nang pantay-pantay sa lahat batay sa pagiging karapat-dapat.",