Spaces:
Running
Running
Commit
·
cc9e528
0
Parent(s):
Initial commit for Gradio Diabetes App
Browse files- .idea/.gitignore +3 -0
- .idea/GRADIO DEMO.iml +10 -0
- .idea/inspectionProfiles/Project_Default.xml +28 -0
- .idea/inspectionProfiles/profiles_settings.xml +6 -0
- .idea/misc.xml +4 -0
- .idea/modules.xml +8 -0
- README.md +11 -0
- app.py +63 -0
- requirements +0 -0
.idea/.gitignore
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
# Default ignored files
|
2 |
+
/shelf/
|
3 |
+
/workspace.xml
|
.idea/GRADIO DEMO.iml
ADDED
@@ -0,0 +1,10 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?xml version="1.0" encoding="UTF-8"?>
|
2 |
+
<module type="PYTHON_MODULE" version="4">
|
3 |
+
<component name="NewModuleRootManager">
|
4 |
+
<content url="file://$MODULE_DIR$">
|
5 |
+
<excludeFolder url="file://$MODULE_DIR$/.venv" />
|
6 |
+
</content>
|
7 |
+
<orderEntry type="inheritedJdk" />
|
8 |
+
<orderEntry type="sourceFolder" forTests="false" />
|
9 |
+
</component>
|
10 |
+
</module>
|
.idea/inspectionProfiles/Project_Default.xml
ADDED
@@ -0,0 +1,28 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<component name="InspectionProjectProfileManager">
|
2 |
+
<profile version="1.0">
|
3 |
+
<option name="myName" value="Project Default" />
|
4 |
+
<inspection_tool class="PyPackageRequirementsInspection" enabled="true" level="WARNING" enabled_by_default="true">
|
5 |
+
<option name="ignoredPackages">
|
6 |
+
<value>
|
7 |
+
<list size="1">
|
8 |
+
<item index="0" class="java.lang.String" itemvalue="tensorflow" />
|
9 |
+
</list>
|
10 |
+
</value>
|
11 |
+
</option>
|
12 |
+
</inspection_tool>
|
13 |
+
<inspection_tool class="PyPep8Inspection" enabled="true" level="WEAK WARNING" enabled_by_default="true">
|
14 |
+
<option name="ignoredErrors">
|
15 |
+
<list>
|
16 |
+
<option value="E305" />
|
17 |
+
</list>
|
18 |
+
</option>
|
19 |
+
</inspection_tool>
|
20 |
+
<inspection_tool class="PyPep8NamingInspection" enabled="true" level="WEAK WARNING" enabled_by_default="true">
|
21 |
+
<option name="ignoredErrors">
|
22 |
+
<list>
|
23 |
+
<option value="N806" />
|
24 |
+
</list>
|
25 |
+
</option>
|
26 |
+
</inspection_tool>
|
27 |
+
</profile>
|
28 |
+
</component>
|
.idea/inspectionProfiles/profiles_settings.xml
ADDED
@@ -0,0 +1,6 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<component name="InspectionProjectProfileManager">
|
2 |
+
<settings>
|
3 |
+
<option name="USE_PROJECT_PROFILE" value="false" />
|
4 |
+
<version value="1.0" />
|
5 |
+
</settings>
|
6 |
+
</component>
|
.idea/misc.xml
ADDED
@@ -0,0 +1,4 @@
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?xml version="1.0" encoding="UTF-8"?>
|
2 |
+
<project version="4">
|
3 |
+
<component name="ProjectRootManager" version="2" project-jdk-name="Python 3.9 (GRADIO DEMO)" project-jdk-type="Python SDK" />
|
4 |
+
</project>
|
.idea/modules.xml
ADDED
@@ -0,0 +1,8 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?xml version="1.0" encoding="UTF-8"?>
|
2 |
+
<project version="4">
|
3 |
+
<component name="ProjectModuleManager">
|
4 |
+
<modules>
|
5 |
+
<module fileurl="file://$PROJECT_DIR$/.idea/GRADIO DEMO.iml" filepath="$PROJECT_DIR$/.idea/GRADIO DEMO.iml" />
|
6 |
+
</modules>
|
7 |
+
</component>
|
8 |
+
</project>
|
README.md
ADDED
@@ -0,0 +1,11 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
# 🩺 Diabetes Risk Predictor
|
2 |
+
|
3 |
+
This app uses a logistic regression model trained on the Pima Indians Diabetes dataset to predict whether a patient is diabetic based on medical features.
|
4 |
+
|
5 |
+
## How to Use
|
6 |
+
|
7 |
+
- Clone or download the repository
|
8 |
+
- Install dependencies: `pip install -r requirements.txt`
|
9 |
+
- Run the app: `python diabetes_app.py`
|
10 |
+
|
11 |
+
Built using Gradio and scikit-learn.
|
app.py
ADDED
@@ -0,0 +1,63 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import pandas as pd
|
2 |
+
from sklearn.model_selection import train_test_split
|
3 |
+
from sklearn.ensemble import RandomForestClassifier
|
4 |
+
from sklearn.metrics import accuracy_score
|
5 |
+
import gradio as gr
|
6 |
+
|
7 |
+
# Load the dataset
|
8 |
+
url = "https://raw.githubusercontent.com/plotly/datasets/master/diabetes.csv"
|
9 |
+
df = pd.read_csv(url)
|
10 |
+
|
11 |
+
|
12 |
+
# Preparing the data
|
13 |
+
X = df.drop("Outcome", axis=1)
|
14 |
+
y = df["Outcome"]
|
15 |
+
|
16 |
+
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2, random_state=42)
|
17 |
+
|
18 |
+
# Training the model
|
19 |
+
model = RandomForestClassifier()
|
20 |
+
model.fit(X_train, y_train)
|
21 |
+
|
22 |
+
# Check accuracy in console
|
23 |
+
y_pred = model.predict(X_test)
|
24 |
+
print("Model trained. Accuracy on test data:", accuracy_score(y_test, y_pred))
|
25 |
+
|
26 |
+
# Gradio prediction function
|
27 |
+
def predict_diabetes(Pregnancies, Glucose, BloodPressure, SkinThickness, Insulin, BMI, DiabetesPedigreeFunction, Age):
|
28 |
+
input_data = [[Pregnancies, Glucose, BloodPressure, SkinThickness,Insulin, BMI, DiabetesPedigreeFunction, Age]]
|
29 |
+
prediction = model.predict(input_data)[0]
|
30 |
+
return "Diabetes" if prediction == 1 else "Not Diabetic"
|
31 |
+
|
32 |
+
# Gradio Interface
|
33 |
+
with gr.Blocks() as iface:
|
34 |
+
gr.Markdown("# 🩺 Diabetes Risk Predictor")
|
35 |
+
gr.Markdown("Enter medical details to predict whether the patient is diabetic.")
|
36 |
+
|
37 |
+
with gr.Row():
|
38 |
+
Pregnancies = gr.Number(label="Pregnancies")
|
39 |
+
Glucose = gr.Number(label="Glucose")
|
40 |
+
BloodPressure = gr.Number(label="BloodPressure")
|
41 |
+
SkinThickness = gr.Number(label="SkinThickness")
|
42 |
+
Insulin = gr.Number(label="Insulin")
|
43 |
+
BMI = gr.Number(label="BMI")
|
44 |
+
DiabetesPedigreeFunction = gr.Number(label="DiabetesPedigreeFunction")
|
45 |
+
Age = gr.Number(label="Age")
|
46 |
+
|
47 |
+
predict_btn = gr.Button("Predict")
|
48 |
+
output = gr.Textbox(label="Prediction")
|
49 |
+
|
50 |
+
def on_click_fn(*args):
|
51 |
+
return predict_diabetes(*args)
|
52 |
+
|
53 |
+
predict_btn.click(
|
54 |
+
on_click_fn,
|
55 |
+
inputs=[
|
56 |
+
Pregnancies, Glucose, BloodPressure, SkinThickness,
|
57 |
+
Insulin, BMI, DiabetesPedigreeFunction, Age
|
58 |
+
],
|
59 |
+
outputs=output
|
60 |
+
)
|
61 |
+
|
62 |
+
iface.launch(share=True)
|
63 |
+
|
requirements
ADDED
File without changes
|