|
import gradio as gr |
|
import joblib |
|
|
|
|
|
model = joblib.load('models/stacking_model.pkl') |
|
vectorizer = joblib.load('models/count_vectorizer.pkl') |
|
|
|
|
|
def predict_class(text): |
|
text_vector = vectorizer.transform([text]) |
|
class_value = model.predict(text_vector)[0] |
|
probability = model.predict_proba(text_vector) |
|
class_name = 'ايجابي' if class_value == 1 else 'سلبي' |
|
return class_name, round(probability[0][class_value], 2) |
|
|
|
|
|
interface = gr.Interface( |
|
fn=predict_class, |
|
inputs="textbox", |
|
outputs=[gr.Textbox(label="التصنيف"), gr.Textbox(label="النسبة")], |
|
title="تصنيف المشاعر", |
|
description="أدخل النص لتحديد المشاعر (إيجابي أو سلبي) والنسبة." |
|
) |
|
|
|
|
|
interface.launch() |
|
|