bartmiller's picture
Update app.py
b7bf350 verified
import streamlit as st
from transformers import pipeline
from sklearn.datasets import fetch_california_housing
from sklearn.model_selection import train_test_split
from sklearn.preprocessing import StandardScaler
from sklearn.linear_model import LinearRegression
from sklearn.metrics import mean_squared_error, r2_score
st.write("begin of house prediction")
st.write("load dataset")
# Load the California Housing dataset
data = fetch_california_housing(as_frame=True)
X = data.data
y = data.target
# Split the dataset into training and test sets
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2, random_state=42)
st.write("standardize")
# Standardize features
scaler = StandardScaler()
X_train = scaler.fit_transform(X_train)
X_test = scaler.transform(X_test)
st.write("train")
# Train the model
model = LinearRegression()
model.fit(X_train, y_train)
st.write("make predictions")
# Make predictions on the test set
y_pred = model.predict(X_test)
st.write("evaluate")
# Evaluate the model
mse = mean_squared_error(y_test, y_pred)
r2 = r2_score(y_test, y_pred)
st.write(f"Mean Squared Error: {mse:.2f}")
st.write(f"R-squared Score: {r2:.2f}")
# print(f"Mean Squared Error: {mse:.2f}")
# print(f"R-squared Score: {r2:.2f}")
st.write("end of house prediction")
sentiment_pipeline = pipeline("sentiment-analysis")
st.title("Sentiment Analysis with HuggingFace Spaces")
st.write("Enter a sentence to analyze its sentiment:")
user_input = st.text_input("")
if user_input:
result = sentiment_pipeline(user_input)
sentiment = result[0]["label"]
confidence = result[0]["score"]
st.write(f"Sentiment: {sentiment}")
st.write(f"Confidence: {confidence:.2f}")