Spaces:
Runtime error
Runtime error
Commit ·
23c4d18
1
Parent(s): 3573bec
Upload Dockerfile, requirements, and streamlit_app.py
Browse files- Dockerfile +19 -0
- requirements.txt +3 -0
- src/app.py +53 -0
Dockerfile
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
|
| 2 |
+
# Use the official Streamlit image
|
| 3 |
+
FROM python:3.10-slim
|
| 4 |
+
|
| 5 |
+
# Set working directory
|
| 6 |
+
WORKDIR /app
|
| 7 |
+
|
| 8 |
+
# Copy app files
|
| 9 |
+
COPY . .
|
| 10 |
+
|
| 11 |
+
# Install dependencies
|
| 12 |
+
RUN pip install --no-cache-dir -r requirements.txt
|
| 13 |
+
|
| 14 |
+
# Expose Streamlit default port
|
| 15 |
+
EXPOSE 7860
|
| 16 |
+
|
| 17 |
+
# Run the Streamlit app
|
| 18 |
+
CMD ["streamlit", "run", "app.py", "--server.port=7860", "--server.enableCORS=false"]
|
| 19 |
+
|
requirements.txt
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
streamlit
|
| 2 |
+
requests
|
| 3 |
+
|
src/app.py
ADDED
|
@@ -0,0 +1,53 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
|
| 2 |
+
import streamlit as st
|
| 3 |
+
import requests
|
| 4 |
+
|
| 5 |
+
st.set_page_config(page_title="Medical Insurance Cost Predictor", layout="centered")
|
| 6 |
+
|
| 7 |
+
st.title("💊 Medical Insurance Cost Predictor")
|
| 8 |
+
|
| 9 |
+
st.markdown("Enter the details below to estimate your medical insurance cost:")
|
| 10 |
+
|
| 11 |
+
# Input fields
|
| 12 |
+
age = st.number_input("Age", min_value=18, max_value=100, value=30)
|
| 13 |
+
sex = st.selectbox("Sex", ["male", "female"])
|
| 14 |
+
bmi = st.number_input("BMI", min_value=10.0, max_value=50.0, value=25.0)
|
| 15 |
+
children = st.number_input("Number of Children", min_value=0, max_value=10, value=1)
|
| 16 |
+
smoker = st.selectbox("Smoker", ["yes", "no"])
|
| 17 |
+
region = st.selectbox("Region", ["northeast", "northwest", "southeast", "southwest"])
|
| 18 |
+
|
| 19 |
+
# Derived features
|
| 20 |
+
region_northwest = 1 if region == "northwest" else 0
|
| 21 |
+
region_southeast = 1 if region == "southeast" else 0
|
| 22 |
+
region_southwest = 1 if region == "southwest" else 0
|
| 23 |
+
bmi_smoker = 1 if smoker == "yes" and bmi > 30 else 0
|
| 24 |
+
obese = 1 if bmi > 30 else 0
|
| 25 |
+
|
| 26 |
+
if st.button("Predict Insurance Cost"):
|
| 27 |
+
input_data = {
|
| 28 |
+
"age": age,
|
| 29 |
+
"sex": sex,
|
| 30 |
+
"bmi": bmi,
|
| 31 |
+
"children": children,
|
| 32 |
+
"smoker": smoker,
|
| 33 |
+
"region_northwest": region_northwest,
|
| 34 |
+
"region_southeast": region_southeast,
|
| 35 |
+
"region_southwest": region_southwest,
|
| 36 |
+
"bmi_smoker": bmi_smoker,
|
| 37 |
+
"obese": obese
|
| 38 |
+
}
|
| 39 |
+
|
| 40 |
+
try:
|
| 41 |
+
# Replace this URL with your actual backend Space URL
|
| 42 |
+
backend_url = "https://<your-backend-username>-insurance-cost-predictor-xgb.hf.space/predict"
|
| 43 |
+
response = requests.post(backend_url, json=input_data)
|
| 44 |
+
|
| 45 |
+
if response.status_code == 200:
|
| 46 |
+
prediction = response.json()["predicted_insurance_cost"]
|
| 47 |
+
st.success(f"💰 Estimated Insurance Cost: ${prediction}")
|
| 48 |
+
else:
|
| 49 |
+
st.error(f"❌ Error from backend: {response.text}")
|
| 50 |
+
|
| 51 |
+
except Exception as e:
|
| 52 |
+
st.error(f"Exception occurred: {e}")
|
| 53 |
+
|