Downloads · 30 days
0
rutujdhodapkar/emotion___
emotion___ is a machine learning model from rutujdhodapkar. Use it for the machine learning task on the model card, and read the license before you ship it in a product.
import gradio as gr import pandas as pd from sklearn.linearmodel import LogisticRegression from sklearn.featureextraction.text import TfidfVectorizer from sklearn.modelselection import traintestsplit import joblib
Downloads · 30 days
0
Access
Public
Updated Jul 25, 2024
Repo size
—
Likes
0
Public
Click a slice to open those files.
.md1.9 KB · 56%
From the Hugging Face model README
import gradio as gr import pandas as pd from sklearn.linear_model import LogisticRegression from sklearn.feature_extraction.text import TfidfVectorizer from sklearn.model_selection import train_test_split import joblib
data_path = 'C:\Users\rutuj\OneDrive\Documents\OneDrive\Desktop\Emotion_final.csv' data = pd.read_csv(data_path)
X = data['Text'] y = data['Emotion']
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2, random_state=42)
vectorizer = TfidfVectorizer() X_train_vec = vectorizer.fit_transform(X_train) X_test_vec = vectorizer.transform(X_test)
logistic_regression_model = LogisticRegression(max_iter=1000)
logistic_regression_model.fit(X_train_vec, y_train)
joblib.dump(logistic_regression_model, 'logistic_regression_model.pkl') joblib.dump(vectorizer, 'vectorizer.pkl')
logistic_regression_model = joblib.load('logistic_regression_model.pkl') vectorizer = joblib.load('vectorizer.pkl')
def predict_emotion_logistic(text): text_vec = vectorizer.transform([text]) prediction = logistic_regression_model.predict(text_vec) return prediction[0]
def predict_emotion_interface(text): predicted_emotion = predict_emotion_logistic(text) return predicted_emotion
iface = gr.Interface( fn=predict_emotion_interface, inputs=gr.inputs.Textbox(lines=2, placeholder="Enter text here..."), outputs="text", title="Emotion Prediction using Logistic Regression", description="Enter text to predict the emotion using a Logistic Regression model.", )
if name == "main": iface.launch()