UmaKumpatla commited on
Commit
4409f18
·
verified ·
1 Parent(s): 6f6f64f

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +33 -37
app.py CHANGED
@@ -1,40 +1,36 @@
1
- import numpy as np
2
- import pandas as pd
3
- import matplotlib.pyplot as plt
4
- import seaborn as sns
5
- import streamlit as st
6
- import joblib
7
- from sklearn.pipeline import Pipeline
8
-
9
- # Load Model
10
- model = joblib.load("rice_model.pkl")
11
-
12
- # Streamlit UI
13
- st.title("Rice Classification App")
14
- st.write("Upload a CSV file containing rice grain properties to predict the type of rice.")
15
-
16
- # File Upload
17
- uploaded_file = st.file_uploader("Upload CSV", type=["csv"])
18
- if uploaded_file is not None:
19
- data = pd.read_csv(uploaded_file)
20
- st.write("### Uploaded Data:")
21
- st.dataframe(data)
22
-
23
- if 'id' in data.columns:
24
- data.drop(columns=['id'], inplace=True)
25
-
26
- if 'Class' in data.columns:
27
- data.drop(columns=['Class'], inplace=True) # Remove target column if present
28
-
29
- # Make Predictions
30
- predictions = model.predict(data)
31
- data['Predicted Class'] = predictions
32
-
33
- st.write("### Predictions:")
34
- st.dataframe(data)
35
-
36
- # Download Predictions
37
- st.download_button(label="Download Predictions", data=data.to_csv(index=False), file_name="predictions.csv", mime="text/csv")
38
 
39
 
40
 
 
1
+ import streamlit as st
2
+ import numpy as np
3
+ import joblib
4
+ import pandas as pd
5
+
6
+ # Load the trained model
7
+ model = joblib.load("rice_model.pkl")
8
+
9
+ # Streamlit UI
10
+ st.title("Rice Classification Model")
11
+ st.write("Enter the grain properties to predict the type of rice.")
12
+
13
+ # User input fields
14
+ area = st.number_input("Area", min_value=1000, max_value=10000, value=5000)
15
+ major_axis_length = st.number_input("Major Axis Length", min_value=50.0, max_value=200.0, value=100.0)
16
+ minor_axis_length = st.number_input("Minor Axis Length", min_value=30.0, max_value=100.0, value=50.0)
17
+ eccentricity = st.number_input("Eccentricity", min_value=0.5, max_value=1.0, value=0.75)
18
+ convex_area = st.number_input("Convex Area", min_value=1000, max_value=10000, value=5000)
19
+ equiv_diameter = st.number_input("Equivalent Diameter", min_value=30.0, max_value=120.0, value=75.0)
20
+ extent = st.number_input("Extent", min_value=0.4, max_value=1.0, value=0.7)
21
+ perimeter = st.number_input("Perimeter", min_value=100.0, max_value=500.0, value=250.0)
22
+ roundness = st.number_input("Roundness", min_value=0.5, max_value=1.0, value=0.75)
23
+ aspect_ratio = st.number_input("Aspect Ratio", min_value=1.0, max_value=3.0, value=1.5)
24
+
25
+ # Predict button
26
+ if st.button("Predict Rice Type"):
27
+ input_features = np.array([[area, major_axis_length, minor_axis_length, eccentricity, convex_area,
28
+ equiv_diameter, extent, perimeter, roundness, aspect_ratio]])
29
+ prediction = model.predict(input_features)[0]
30
+ rice_type = "Type 1" if prediction == 1 else "Type 0"
31
+ st.success(f"Predicted Rice Type: {rice_type}")
32
+
33
+ # Run using: streamlit run app.py
 
 
 
 
34
 
35
 
36