Spaces:
Sleeping
Sleeping
| { | |
| "cells": [ | |
| { | |
| "cell_type": "code", | |
| "execution_count": null, | |
| "id": "728431f5", | |
| "metadata": {}, | |
| "outputs": [], | |
| "source": [] | |
| }, | |
| { | |
| "cell_type": "code", | |
| "execution_count": 1, | |
| "id": "fd56baf1", | |
| "metadata": {}, | |
| "outputs": [ | |
| { | |
| "name": "stderr", | |
| "output_type": "stream", | |
| "text": [ | |
| "2023-12-25 15:31:55.354 \n", | |
| " \u001b[33m\u001b[1mWarning:\u001b[0m to view this Streamlit app on a browser, run it with the following\n", | |
| " command:\n", | |
| "\n", | |
| " streamlit run C:\\Users\\user\\anaconda3\\Lib\\site-packages\\ipykernel_launcher.py [ARGUMENTS]\n" | |
| ] | |
| } | |
| ], | |
| "source": [ | |
| "import streamlit as st\n", | |
| "import pandas as pd\n", | |
| "import joblib\n", | |
| "\n", | |
| "# Load trained model\n", | |
| "model = joblib.load('mpg_model.pkl') # Ensure this path is correct\n", | |
| "\n", | |
| "def user_input_features():\n", | |
| " cylinders = st.sidebar.slider('Cylinders', 3, 8, 4)\n", | |
| " displacement = st.sidebar.number_input('Displacement')\n", | |
| " horsepower = st.sidebar.number_input('Horsepower')\n", | |
| " weight = st.sidebar.number_input('Weight')\n", | |
| " acceleration = st.sidebar.number_input('Acceleration')\n", | |
| " model_year = st.sidebar.slider('Model Year', 70, 82, 76)\n", | |
| " data = {'cylinders': cylinders,\n", | |
| " 'displacement': displacement,\n", | |
| " 'horsepower': horsepower,\n", | |
| " 'weight': weight,\n", | |
| " 'acceleration': acceleration,\n", | |
| " 'model_year': model_year}\n", | |
| " features = pd.DataFrame(data, index=[0])\n", | |
| " return features\n", | |
| "\n", | |
| "# Main Streamlit app interface\n", | |
| "st.write(\"\"\"\n", | |
| "# Simple MPG Prediction App\n", | |
| "This app predicts the **Miles Per Gallon (MPG)** of your car!\n", | |
| "\"\"\")\n", | |
| "\n", | |
| "# User input features\n", | |
| "input_df = user_input_features()\n", | |
| "\n", | |
| "# Display the user input features\n", | |
| "st.subheader('User Input features')\n", | |
| "st.write(input_df)\n", | |
| "\n", | |
| "# Predict and display the output\n", | |
| "st.subheader('Prediction')\n", | |
| "prediction = model.predict(input_df)\n", | |
| "st.write(f'Predicted MPG: {prediction[0]:.2f}')" | |
| ] | |
| }, | |
| { | |
| "cell_type": "code", | |
| "execution_count": null, | |
| "id": "f8836f1f", | |
| "metadata": {}, | |
| "outputs": [], | |
| "source": [] | |
| } | |
| ], | |
| "metadata": { | |
| "kernelspec": { | |
| "display_name": "Python 3 (ipykernel)", | |
| "language": "python", | |
| "name": "python3" | |
| }, | |
| "language_info": { | |
| "codemirror_mode": { | |
| "name": "ipython", | |
| "version": 3 | |
| }, | |
| "file_extension": ".py", | |
| "mimetype": "text/x-python", | |
| "name": "python", | |
| "nbconvert_exporter": "python", | |
| "pygments_lexer": "ipython3", | |
| "version": "3.11.5" | |
| } | |
| }, | |
| "nbformat": 4, | |
| "nbformat_minor": 5 | |
| } | |