File size: 991 Bytes
e8ed137
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import gradio as gr
import joblib

# Load the pre-trained model and vectorizer
model = joblib.load('models/stacking_model.pkl')
vectorizer = joblib.load('models/count_vectorizer.pkl')

# Define the prediction function
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)

# Create the Gradio interface
interface = gr.Interface(
    fn=predict_class,
    inputs="textbox",  # Input is a textbox where users input their text
    outputs=[gr.Textbox(label="التصنيف"), gr.Textbox(label="النسبة")],  # Output labels for class and probability
    title="تصنيف المشاعر",
    description="أدخل النص لتحديد المشاعر (إيجابي أو سلبي) والنسبة."
)

# Launch the Gradio app
interface.launch()