phoner45 commited on
Commit
f97ece8
·
verified ·
1 Parent(s): 86e9fe3

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +4 -36
app.py CHANGED
@@ -3,8 +3,6 @@ import numpy as np
3
  import joblib
4
  from fastapi import FastAPI, HTTPException
5
  from pydantic import BaseModel
6
- import uvicorn
7
- import streamlit as st
8
 
9
  # Load model from the local storage (ensure the model file is in the same directory)
10
  model_path = "model.pkl"
@@ -13,39 +11,6 @@ gb_model_loaded = joblib.load(model_path)
13
  # Create FastAPI app
14
  app = FastAPI()
15
 
16
- # Set the title of the app
17
- st.title("Medical Prediction Model")
18
-
19
- # Instruction text
20
- st.write("Enter 32 features for prediction:")
21
-
22
- # Create 32 input fields for user input
23
- inputs = []
24
- for i in range(32):
25
- value = st.number_input(f"Feature {i + 1}", min_value=0, step=1)
26
- inputs.append(value)
27
-
28
- # Button to make prediction
29
- if st.button("Predict"):
30
- # Prepare the data for the request
31
- input_data = {"features": inputs}
32
-
33
- # Set the URL for your Hugging Face Space
34
- url = "https://phoner45-mediguide-api.hf.space/predict" # Replace with your actual Space URL
35
-
36
- # Make a POST request
37
- response = requests.post(url, json=inputs)
38
-
39
- # Check the response status code
40
- if response.status_code == 200:
41
- # Get the JSON response
42
- prediction = response.json()
43
- # Display the prediction results
44
- st.success("Prediction Results:")
45
- st.json(prediction)
46
- else:
47
- st.error(f"Error: {response.status_code} - {response.text}")
48
-
49
  # Define class labels
50
  class_names = [
51
  'Emergency & Accident Unit', 'Heart Clinic',
@@ -82,6 +47,9 @@ def predict(data: InputData):
82
  except Exception as e:
83
  raise HTTPException(status_code=500, detail=str(e))
84
 
85
- # Run the application with the following command if needed
 
86
  # if __name__ == "__main__":
 
87
  # uvicorn.run(app, host="0.0.0.0", port=8501)
 
 
3
  import joblib
4
  from fastapi import FastAPI, HTTPException
5
  from pydantic import BaseModel
 
 
6
 
7
  # Load model from the local storage (ensure the model file is in the same directory)
8
  model_path = "model.pkl"
 
11
  # Create FastAPI app
12
  app = FastAPI()
13
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
14
  # Define class labels
15
  class_names = [
16
  'Emergency & Accident Unit', 'Heart Clinic',
 
47
  except Exception as e:
48
  raise HTTPException(status_code=500, detail=str(e))
49
 
50
+ # To run the FastAPI app locally for testing
51
+ # Uncomment the following lines
52
  # if __name__ == "__main__":
53
+ # import uvicorn
54
  # uvicorn.run(app, host="0.0.0.0", port=8501)
55
+