danialsiddiqui commited on
Commit
d19af3d
·
1 Parent(s): 0ceff79

Add Streamlit UI

Browse files
Files changed (3) hide show
  1. Dockerfile +4 -4
  2. requirements.txt +1 -0
  3. streamlit_app.py +36 -13
Dockerfile CHANGED
@@ -2,9 +2,9 @@ FROM python:3.9
2
 
3
  WORKDIR /app
4
 
5
- COPY requirements.txt .
6
- RUN pip install --no-cache-dir -r requirements.txt
7
 
8
- COPY . .
9
 
10
- CMD ["uvicorn", "app:app", "--host", "0.0.0.0", "--port", "7860"]
 
2
 
3
  WORKDIR /app
4
 
5
+ COPY requirements.txt requirements.txt
6
+ RUN pip install --no-cache-dir --upgrade -r requirements.txt
7
 
8
+ COPY . /app
9
 
10
+ CMD ["streamlit", "run", "streamlit_app.py", "--server.port=7860", "--server.address=0.0.0.0"]
requirements.txt CHANGED
@@ -5,3 +5,4 @@ joblib
5
  pandas
6
  numpy
7
  scikit-learn
 
 
5
  pandas
6
  numpy
7
  scikit-learn
8
+ streamlit
streamlit_app.py CHANGED
@@ -1,18 +1,41 @@
1
  import streamlit as st
2
- import requests
 
 
3
 
4
- st.title("Supermarket Sales Forecast")
 
 
 
 
5
 
6
- # Input sliders or number inputs
7
- feature1 = st.number_input("Feature 1")
8
- feature2 = st.number_input("Feature 2")
9
- feature3 = st.number_input("Feature 3")
 
 
 
 
 
10
 
11
  if st.button("Predict"):
12
- data = {
13
- "feature1": feature1,
14
- "feature2": feature2,
15
- "feature3": feature3
16
- }
17
- response = requests.post("https://YOUR_DEPLOYED_API_URL/predict", json=data)
18
- st.write("Prediction:", response.json()["prediction"])
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  import streamlit as st
2
+ import joblib
3
+ import pandas as pd
4
+ from huggingface_hub import hf_hub_download
5
 
6
+ # Load model from your HF repo
7
+ model_file = hf_hub_download(repo_id="danialsiddiqui/task6-model", filename="model.joblib")
8
+ model_data = joblib.load(model_file)
9
+ model = model_data["model"]
10
+ columns = model_data["columns"]
11
 
12
+ st.title("Supermarket Revenue Prediction")
13
+
14
+ # Input fields
15
+ gender = st.selectbox("Gender", ["Male", "Female"])
16
+ customer_type = st.selectbox("Customer Type", ["Member", "Normal"])
17
+ product_line = st.selectbox("Product Line", ["Beverages", "Food", "Health and beauty", "Fashion", "Electronics", "Home and lifestyle", "Sports and travel"])
18
+ unit_price = st.number_input("Unit Price", min_value=0.0, value=10.0)
19
+ quantity = st.number_input("Quantity", min_value=1, value=1)
20
+ tax_5 = st.number_input("Tax 5%", min_value=0.0, value=0.0)
21
 
22
  if st.button("Predict"):
23
+ # Create dataframe
24
+ df = pd.DataFrame([{
25
+ "gender": gender,
26
+ "customer_type": customer_type,
27
+ "product_line": product_line,
28
+ "unit_price": unit_price,
29
+ "quantity": quantity,
30
+ "tax_5": tax_5
31
+ }])
32
+
33
+ # One-hot encode same as training
34
+ df = pd.get_dummies(df)
35
+ for col in columns:
36
+ if col not in df.columns:
37
+ df[col] = 0
38
+ df = df[columns]
39
+
40
+ prediction = model.predict(df)[0]
41
+ st.success(f"Predicted Revenue: {prediction:.2f}")