|
import gradio as gr |
|
from transformers import TFAutoModelForSequenceClassification, AutoTokenizer |
|
import tensorflow as tf |
|
|
|
model = TFAutoModelForSequenceClassification.from_pretrained("Serhii228/ukrainian-question-statement-classifier") |
|
tokenizer = AutoTokenizer.from_pretrained("Serhii228/ukrainian-question-statement-classifier") |
|
|
|
def classify(text): |
|
inputs = tokenizer(text, return_tensors="tf", truncation=True, padding=True) |
|
outputs = model(**inputs) |
|
prob = tf.nn.sigmoid(outputs.logits).numpy()[0][0] |
|
label = "🟢 Питання (1)" if prob > 0.5 else "🔵 Твердження (0)" |
|
return f"{label} — ймовірність: {prob:.2f}" |
|
|
|
demo = gr.Interface( |
|
fn=classify, |
|
inputs=gr.Textbox(lines=2, placeholder="Введіть українське речення..."), |
|
outputs="text", |
|
title="🇺🇦 Ukrainian Question Classifier", |
|
description="Визначає, чи є фраза питанням або твердженням." |
|
) |
|
|
|
demo.launch() |
|
|