CoolFace
Apppublic

bartmiller/SentimentAnalysis

sourceHugging Faceupdated 2y agoView on Hugging Face
0likes
app.py60 linesDownload Raw Back to root
1import streamlit as st2from transformers import pipeline3 4from sklearn.datasets import fetch_california_housing5from sklearn.model_selection import train_test_split6from sklearn.preprocessing import StandardScaler7from sklearn.linear_model import LinearRegression8from sklearn.metrics import mean_squared_error, r2_score9 10st.write("begin of house prediction")11st.write("load dataset")12# Load the California Housing dataset13data = fetch_california_housing(as_frame=True)14X = data.data15y = data.target16 17# Split the dataset into training and test sets18X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2, random_state=42)19 20st.write("standardize")21# Standardize features22scaler = StandardScaler()23X_train = scaler.fit_transform(X_train)24X_test = scaler.transform(X_test)25 26st.write("train")27# Train the model28model = LinearRegression()29model.fit(X_train, y_train)30 31st.write("make predictions")32# Make predictions on the test set33y_pred = model.predict(X_test)34 35st.write("evaluate")36# Evaluate the model37mse = mean_squared_error(y_test, y_pred)38r2 = r2_score(y_test, y_pred)39 40st.write(f"Mean Squared Error: {mse:.2f}")41st.write(f"R-squared Score: {r2:.2f}")42         43# print(f"Mean Squared Error: {mse:.2f}")44# print(f"R-squared Score: {r2:.2f}")45 46st.write("end of house prediction")47 48sentiment_pipeline = pipeline("sentiment-analysis")49 50st.title("Sentiment Analysis with HuggingFace Spaces")51st.write("Enter a sentence to analyze its sentiment:")52 53user_input = st.text_input("")54if user_input:55    result = sentiment_pipeline(user_input)56    sentiment = result[0]["label"]57    confidence = result[0]["score"]58 59    st.write(f"Sentiment: {sentiment}")60    st.write(f"Confidence: {confidence:.2f}")