Spaces:
Runtime error
Runtime error
File size: 2,587 Bytes
4938fc2 df4c9ba f4ecb39 1589ac0 4938fc2 f4ecb39 4938fc2 f4ecb39 4938fc2 df4c9ba 4938fc2 df4c9ba 4938fc2 df4c9ba 4938fc2 a2d00bf df4c9ba 4938fc2 a2d00bf 4938fc2 1589ac0 4938fc2 df4c9ba 4d18ff9 e58d1b1 4d18ff9 4938fc2 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 |
import gradio as gr
import time
from optimum.intel.openvino import OVModelForSequenceClassification
from transformers import AutoModelForSequenceClassification, AutoTokenizer, pipeline
model_id = "juliensimon/xlm-v-base-language-id"
ov_model = OVModelForSequenceClassification.from_pretrained(
model_id, from_transformers=True
)
tokenizer = AutoTokenizer.from_pretrained(model_id)
p = pipeline("text-classification", model=ov_model, tokenizer=tokenizer)
# Warmum
for i in range(100):
p("Hello world")
def process(text, top_k=5):
tick = time.time()
pred = p(text, top_k=top_k)
tock = time.time()
scores = {x["label"]: x["score"] for x in pred}
msg = f'{(tock-tick)*1000:.2f} milliseconds'
return scores, msg
# Gradio inputs
input_text = gr.Text(label="Enter text")
# Gradio outputs
labels = gr.Label(label="Languages", num_top_classes=5)
output_text = gr.Text(label="Predition time")
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."
iface = gr.Interface(
description=description,
fn=process,
inputs=input_text,
outputs=[labels, output_text],
examples=[
"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",
"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.",
"Každý má právo na vzdělání. Vzdělání nechť je bezplatné, alespoň v počátečních a základních stupních. Základní vzdělání je povinné. Technické a odborné vzdělání budiž všeobecně přístupné a rovněž vyšší vzdělání má být stejně přístupné všem podle schopností.",
"Baat yii laa mën a wax ci jéego yi Marubba Faal séqi jëm ci bindkat yi taamu làmmiñi réew mi. Am naa ci mbégte lool, ngir yàgg naa ko wax ne bumu xeeb li gafakaam dencal xam-xam yu bawoo ca Maam. Téere bii mu tudde Yóbbalu Ndaw firndeel na sama njort.",
],
allow_flagging="never",
)
iface.launch()
|