Zen-4011 commited on
Commit
01a92ee
·
verified ·
1 Parent(s): 7a79f42

Update src/streamlit_app.py

Browse files
Files changed (1) hide show
  1. src/streamlit_app.py +33 -90
src/streamlit_app.py CHANGED
@@ -1,98 +1,41 @@
1
- # Libraries
2
  import streamlit as st
 
3
  import pandas as pd
4
- from sklearn.model_selection import train_test_split
5
- from sklearn.ensemble import RandomForestClassifier
6
- from sklearn.metrics import accuracy_score
7
 
8
- # Title
9
- st.title("Diabetes Prediction System")
10
- st.write("A Machine Learning model trained on the PIMA Indians Diabetes Dataset.")
11
 
12
- # Load data and Train Data
13
- @st.cache_resource
14
- def train_model():
15
- try:
16
- df = pd.read_csv("diabetes.csv")
17
- except FileNotFoundError:
18
- # We create a tiny dummy dataset.
19
- # This prevents the app from crashing.
20
- st.warning("'diabetes.csv' not found. Using dummy data for demonstration.")
21
- data = {
22
- 'Pregnancies': [6, 1, 8, 1, 0, 5, 3, 10],
23
- 'Glucose': [148, 85, 183, 89, 137, 116, 78, 115],
24
- 'BloodPressure': [72, 66, 64, 66, 40, 74, 50, 0],
25
- 'SkinThickness': [35, 29, 0, 23, 35, 0, 32, 0],
26
- 'Insulin': [0, 0, 0, 94, 168, 0, 88, 0],
27
- 'BMI': [33.6, 26.6, 23.3, 28.1, 43.1, 25.6, 31.0, 35.3],
28
- 'DiabetesPedigreeFunction': [0.627, 0.351, 0.672, 0.167, 2.288, 0.201, 0.248, 0.134],
29
- 'Age': [50, 31, 32, 21, 33, 30, 26, 29],
30
- 'Outcome': [1, 0, 1, 0, 1, 0, 1, 0]
31
- }
32
- df = pd.DataFrame(data)
33
-
34
- # Data Split
35
- X = df.drop(columns=['Outcome'])
36
- y = df['Outcome']
37
- X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2, random_state=42)
38
-
39
- # Train Model
40
- model = RandomForestClassifier(random_state=42)
41
- model.fit(X_train, y_train)
42
-
43
- # Calculate accuracy
44
- acc = accuracy_score(y_test, model.predict(X_test))
45
-
46
- return model, acc
47
-
48
- # Loading the Model
49
- model, accuracy = train_model()
50
 
51
- # Display Model Accuracy
52
- st.write(f"**Model Accuracy:** {accuracy * 100:.2f}%")
53
- st.markdown("---")
 
54
 
55
- # UI
56
- st.sidebar.header("Patient Data")
 
 
 
 
 
 
 
57
 
58
- def user_input_features():
59
- pregnancies = st.sidebar.slider('Pregnancies', 0, 17, 3)
60
- glucose = st.sidebar.slider('Glucose', 0, 199, 117)
61
- bp = st.sidebar.slider('Blood Pressure', 0, 122, 72)
62
- skin = st.sidebar.slider('Skin Thickness', 0, 99, 23)
63
- insulin = st.sidebar.slider('Insulin', 0, 846, 30)
64
- bmi = st.sidebar.slider('BMI', 0.0, 67.1, 32.0)
65
- dpf = st.sidebar.slider('Diabetes Pedigree Function', 0.078, 2.42, 0.3725)
66
- age = st.sidebar.slider('Age', 21, 81, 29)
67
 
68
- data = {
69
- 'Pregnancies': pregnancies,
70
- 'Glucose': glucose,
71
- 'BloodPressure': bp,
72
- 'SkinThickness': skin,
73
- 'Insulin': insulin,
74
- 'BMI': bmi,
75
- 'DiabetesPedigreeFunction': dpf,
76
- 'Age': age
77
- }
78
- features = pd.DataFrame(data, index=[0])
79
- return features
80
-
81
- input_df = user_input_features()
82
-
83
- # Display User Input
84
- st.subheader('User Input parameters')
85
- st.write(input_df)
86
-
87
- # Prediction
88
- if st.button('Predict Diabetes Risk'):
89
- prediction = model.predict(input_df)
90
- prediction_proba = model.predict_proba(input_df)
91
-
92
- st.subheader('Prediction Result')
93
- if prediction[0] == 1:
94
- st.error('Positive (High Risk of Diabetes)')
95
- else:
96
- st.success('Negative (Low Risk of Diabetes)')
97
-
98
- st.write(f"Probability: {prediction_proba[0][prediction[0]] * 100:.2f}%")
 
 
1
  import streamlit as st
2
+ import os
3
  import pandas as pd
 
 
 
4
 
5
+ st.title("🕵️ File Finder Tool")
 
 
6
 
7
+ st.write("Current Working Directory:", os.getcwd())
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
8
 
9
+ # 1. List ALL files in the entire container (Recursive Search)
10
+ st.subheader("Scanning for 'diabetes.csv'...")
11
+ found = False
12
+ csv_path = ""
13
 
14
+ # Walk through every folder in the app
15
+ for root, dirs, files in os.walk("."):
16
+ for file in files:
17
+ # Check if the file name contains 'diabetes' (case insensitive)
18
+ if "diabetes" in file.lower():
19
+ full_path = os.path.join(root, file)
20
+ st.success(f"✅ FOUND IT! Path: `{full_path}`")
21
+ found = True
22
+ csv_path = full_path
23
 
24
+ if not found:
25
+ st.error("❌ logical_error: The file 'diabetes.csv' is NOT in the container.")
26
+ st.warning("Make sure you didn't name it 'Diabetes.csv' (Capital D) or 'diabetes.csv.txt'.")
 
 
 
 
 
 
27
 
28
+ st.subheader("Listing ALL files I can see:")
29
+ # List all files so you can see what IS there
30
+ for root, dirs, files in os.walk("."):
31
+ for file in files:
32
+ st.code(os.path.join(root, file))
33
+ else:
34
+ # 2. Try to load it using the path we found
35
+ st.subheader("Trying to load data...")
36
+ try:
37
+ df = pd.read_csv(csv_path)
38
+ st.write("Preview of data:", df.head())
39
+ st.success("🎉 It works! Now you know the correct path to use.")
40
+ except Exception as e:
41
+ st.error(f"Found the file but failed to read it: {e}")