jonathanagustin commited on
Commit
1bf7613
1 Parent(s): 6934ba8

Upload folder using huggingface_hub

Browse files
Files changed (2) hide show
  1. app.py +17 -17
  2. requirements.txt +3 -2
app.py CHANGED
@@ -1,13 +1,15 @@
1
  import logging
2
- import requests
3
  import gradio as gr
 
 
4
 
5
  # Set up logging
6
  logging.basicConfig(level=logging.INFO)
7
  logger = logging.getLogger(__name__)
8
 
9
- # Configuration for the model
10
- API_URL = "https://api-inference.huggingface.co/models/aai540-group3/diabetes-readmission"
 
11
 
12
  # Define constants for the Gradio interface
13
  AGE_RANGE = (0, 100)
@@ -24,15 +26,15 @@ def predict(
24
  glipizide, glyburide, pioglitazone, rosiglitazone, acarbose, insulin,
25
  readmitted
26
  ):
27
- # Create a dictionary from the input features
28
- input_data = {
29
  "age": age,
30
  "time_in_hospital": time_in_hospital,
31
  "num_procedures": num_procedures,
32
  "num_medications": num_medications,
33
  "number_diagnoses": number_diagnoses,
34
  "metformin": int(metformin),
35
- "repaglinide": int(repaglinide),
36
  "nateglinide": int(nateglinide),
37
  "chlorpropamide": int(chlorpropamide),
38
  "glimepiride": int(glimepiride),
@@ -42,20 +44,18 @@ def predict(
42
  "rosiglitazone": int(rosiglitazone),
43
  "acarbose": int(acarbose),
44
  "insulin": int(insulin),
45
- "readmitted": readmitted # Ensure this is correctly mapped
46
- }
47
 
48
  try:
49
- # Make a request to the Hugging Face inference API
50
- response = requests.post(API_URL, json={"inputs": input_data})
51
- response.raise_for_status() # Raise an error for bad responses
52
-
53
- prediction = response.json()
54
  logger.info(f"Prediction received: {prediction}")
55
- return f"<h1 style='font-size: 48px; color: green;'>Prediction: {prediction}</h1>"
56
 
57
- except requests.exceptions.RequestException as e:
58
- logger.error(f"Error in API request: {e}")
 
 
59
  return "<h1 style='font-size: 48px; color: red;'>Error in prediction</h1>"
60
 
61
  # Create Gradio interface
@@ -87,4 +87,4 @@ iface = gr.Interface(
87
 
88
  # Launch the Gradio app
89
  if __name__ == "__main__":
90
- iface.launch()
 
1
  import logging
 
2
  import gradio as gr
3
+ import pandas as pd
4
+ from autogluon.tabular import TabularPredictor
5
 
6
  # Set up logging
7
  logging.basicConfig(level=logging.INFO)
8
  logger = logging.getLogger(__name__)
9
 
10
+ # Load the AutoGluon model from the Hugging Face Hub
11
+ MODEL_ID = "aai540-group3/diabetes-readmission"
12
+ predictor = TabularPredictor.load(MODEL_ID)
13
 
14
  # Define constants for the Gradio interface
15
  AGE_RANGE = (0, 100)
 
26
  glipizide, glyburide, pioglitazone, rosiglitazone, acarbose, insulin,
27
  readmitted
28
  ):
29
+ # Create a DataFrame from the input features
30
+ input_data = pd.DataFrame([{
31
  "age": age,
32
  "time_in_hospital": time_in_hospital,
33
  "num_procedures": num_procedures,
34
  "num_medications": num_medications,
35
  "number_diagnoses": number_diagnoses,
36
  "metformin": int(metformin),
37
+ "repaglinide": int(repaginide),
38
  "nateglinide": int(nateglinide),
39
  "chlorpropamide": int(chlorpropamide),
40
  "glimepiride": int(glimepiride),
 
44
  "rosiglitazone": int(rosiglitazone),
45
  "acarbose": int(acarbose),
46
  "insulin": int(insulin),
47
+ "readmitted": readmitted
48
+ }])
49
 
50
  try:
51
+ # Make a prediction using the AutoGluon predictor
52
+ prediction = predictor.predict(input_data)
 
 
 
53
  logger.info(f"Prediction received: {prediction}")
 
54
 
55
+ return f"<h1 style='font-size: 48px; color: green;'>Prediction: {prediction.iloc[0]}</h1>"
56
+
57
+ except Exception as e:
58
+ logger.error(f"Error in prediction: {e}")
59
  return "<h1 style='font-size: 48px; color: red;'>Error in prediction</h1>"
60
 
61
  # Create Gradio interface
 
87
 
88
  # Launch the Gradio app
89
  if __name__ == "__main__":
90
+ iface.launch()
requirements.txt CHANGED
@@ -1,2 +1,3 @@
1
- requests
2
- pandas
 
 
1
+ autogluon
2
+ gradio
3
+ pandas