|
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") |
|
|
|
data = fetch_california_housing(as_frame=True) |
|
X = data.data |
|
y = data.target |
|
|
|
|
|
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2, random_state=42) |
|
|
|
st.write("standardize") |
|
|
|
scaler = StandardScaler() |
|
X_train = scaler.fit_transform(X_train) |
|
X_test = scaler.transform(X_test) |
|
|
|
st.write("train") |
|
|
|
model = LinearRegression() |
|
model.fit(X_train, y_train) |
|
|
|
st.write("make predictions") |
|
|
|
y_pred = model.predict(X_test) |
|
|
|
st.write("evaluate") |
|
|
|
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}") |
|
|
|
|
|
|
|
|
|
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}") |