File size: 1,007 Bytes
5f631ab
 
 
 
 
 
58180bc
5f631ab
 
 
58180bc
5f631ab
58180bc
5f631ab
 
 
 
58180bc
5f631ab
 
b037c4e
5f631ab
 
58180bc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
import gradio as gr
from tensorflow.keras.models import load_model
from sentence_transformers import SentenceTransformer
import numpy as np

embedder = SentenceTransformer('all-MiniLM-L6-v2')
model = load_model("Model.h5")

def classify_sentiment(text):
    embedding = embedder.encode(text, show_progress_bar=False)
    embedding = np.expand_dims(embedding, axis=0)  # (1, 384)
    pred = model.predict(embedding)[0][0]
    label = "Positive" if pred > 0.5 else "Negative"
    return f"Prediction: {label} (Score: {pred:.2f})"

interface = gr.Interface(
    fn=classify_sentiment,
    inputs=gr.Textbox(lines=2, placeholder="Enter a tweet..."),
    outputs=gr.Textbox(),
    title="Tweet Sentiment Classifier",
    description="Uses all-MiniLM-L6-v2 to convert your text into a meaningful vector and then classifies it as positive or negative sentiment using a trained deep Sequential model. 👉 [View Source on GitHub](https://github.com/nishantksingh0/Twitter-Sentiment-Analysis)",
)

interface.launch()