File size: 537 Bytes
125ef8b
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
import numpy as np
import gradio as gr
import joblib

nb_classifier = joblib.load('nb_classifier.pkl')
tfidf_vectorizer = joblib.load('tfidf_vectorizer.pkl')

def predict_sentiment(text):
    text_tfidf = tfidf_vectorizer.transform([text])
    predicted_sentiment = nb_classifier.predict(text_tfidf)[0]
    return predicted_sentiment

iface = gr.Interface(
    fn=predict_sentiment,
    inputs="text",
    outputs="text",
    title="Sentiment Analysis",
    description="Predict sentiment of a text message.",
)

iface.launch(share=True)