mennabar4a8 commited on
Commit
756b493
·
verified ·
1 Parent(s): dc04163

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +7 -44
app.py CHANGED
@@ -1,49 +1,29 @@
1
  # Importing libraries
2
- import os
3
- import uuid
4
  import joblib
5
- import json
6
  import gradio as gr
7
  import pandas as pd
8
 
9
- from huggingface_hub import CommitScheduler
10
- from pathlib import Path
11
-
12
-
13
- log_file = Path("logs/") / f"data_{uuid.uuid4()}.json"
14
- log_folder = log_file.parent
15
-
16
- scheduler = CommitScheduler(
17
- repo_id="Insurance_Charge_Prediction_Project",
18
- repo_type="dataset",
19
- folder_path=log_folder,
20
- path_in_repo="data",
21
- every=2
22
- )
23
-
24
  charges_predictor = joblib.load("model.joblib")
25
 
26
 
27
- # Inputs
28
-
29
  age_input = gr.Number(label="Age", value=25)
30
  bmi_input = gr.Number(label="BMI", value=25)
31
  children_input = gr.Number(label="Children", value=0)
32
 
33
  sex_input = gr.Dropdown(
34
- ["male", "female"],
35
  value="male",
36
  label="Sex"
37
  )
38
 
39
  smoker_input = gr.Dropdown(
40
- ["yes", "no"],
41
  value="no",
42
  label="Smoker"
43
  )
44
 
45
  region_input = gr.Dropdown(
46
- ["southeast", "southwest", "northeast", "northwest"],
47
  value="southeast",
48
  label="Region"
49
  )
@@ -52,7 +32,7 @@ region_input = gr.Dropdown(
52
  model_output = gr.Textbox(label="Predicted Insurance Cost")
53
 
54
 
55
- def predict_charges(age, bmi, children, sex, smoker, region):
56
 
57
  sample = {
58
  "age": age,
@@ -65,20 +45,7 @@ def predict_charges(age, bmi, children, sex, smoker, region):
65
 
66
  data_point = pd.DataFrame([sample])
67
 
68
- prediction = charges_predictor.predict(data_point).tolist()
69
-
70
- with scheduler.lock:
71
- with log_file.open("a") as f:
72
- f.write(json.dumps({
73
- "age": age,
74
- "bmi": bmi,
75
- "children": children,
76
- "sex": sex,
77
- "smoker": smoker,
78
- "region": region,
79
- "prediction": prediction[0]
80
- }))
81
- f.write("\n")
82
 
83
  return f"${prediction[0]:,.2f}"
84
 
@@ -94,12 +61,8 @@ demo = gr.Interface(
94
  region_input
95
  ],
96
  outputs=model_output,
97
- title="HealthyLife Insurance Charge Prediction",
98
- description="Predict the insurance medical charges based on patient information",
99
- flagging_mode="manual",
100
- concurrency_limit=8
101
  )
102
 
103
-
104
- demo.queue()
105
  demo.launch()
 
1
  # Importing libraries
 
 
2
  import joblib
 
3
  import gradio as gr
4
  import pandas as pd
5
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
6
  charges_predictor = joblib.load("model.joblib")
7
 
8
 
 
 
9
  age_input = gr.Number(label="Age", value=25)
10
  bmi_input = gr.Number(label="BMI", value=25)
11
  children_input = gr.Number(label="Children", value=0)
12
 
13
  sex_input = gr.Dropdown(
14
+ ["male","female"],
15
  value="male",
16
  label="Sex"
17
  )
18
 
19
  smoker_input = gr.Dropdown(
20
+ ["yes","no"],
21
  value="no",
22
  label="Smoker"
23
  )
24
 
25
  region_input = gr.Dropdown(
26
+ ["southeast","southwest","northeast","northwest"],
27
  value="southeast",
28
  label="Region"
29
  )
 
32
  model_output = gr.Textbox(label="Predicted Insurance Cost")
33
 
34
 
35
+ def predict_charges(age,bmi,children,sex,smoker,region):
36
 
37
  sample = {
38
  "age": age,
 
45
 
46
  data_point = pd.DataFrame([sample])
47
 
48
+ prediction = charges_predictor.predict(data_point)
 
 
 
 
 
 
 
 
 
 
 
 
 
49
 
50
  return f"${prediction[0]:,.2f}"
51
 
 
61
  region_input
62
  ],
63
  outputs=model_output,
64
+ title="Insurance Charge Prediction",
65
+ description="Predict insurance medical charges based on user information"
 
 
66
  )
67
 
 
 
68
  demo.launch()