Spaces:
Sleeping
Sleeping
File size: 986 Bytes
6bb6e17 e61efde 6bb6e17 e61efde 6bb6e17 75ed04e 6bb6e17 e61efde 75ed04e 6bb6e17 |
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 |
import gradio as gr
from transformers import AutoTokenizer, AutoModelForSequenceClassification, pipeline
tokenizer = AutoTokenizer.from_pretrained("ua-l/is-legal-question")
model = AutoModelForSequenceClassification.from_pretrained(
"ua-l/is-legal-question"
)
topic_classifier = pipeline(
task="text-classification", model=model, tokenizer=tokenizer, device="cpu", top_k=5
)
def predict(question):
predictions = topic_classifier(question)
topics = []
for prediction in predictions[0]:
label = prediction["label"]
probability = round(prediction["score"] * 100, 2)
topics.append(
{
"label": label,
"probability": probability,
}
)
return topics
inputs = gr.Textbox(lines=2, label="Enter the question", value="Як отримати виплати ВПО?")
outputs = gr.JSON(label="Output")
demo = gr.Interface(fn=predict, inputs=inputs, outputs=outputs)
demo.launch() |