Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -4,6 +4,7 @@ import joblib
|
|
| 4 |
from fastapi import FastAPI, HTTPException
|
| 5 |
from pydantic import BaseModel
|
| 6 |
import uvicorn
|
|
|
|
| 7 |
|
| 8 |
# Load model from the local storage (ensure the model file is in the same directory)
|
| 9 |
model_path = "model.pkl"
|
|
@@ -12,6 +13,39 @@ gb_model_loaded = joblib.load(model_path)
|
|
| 12 |
# Create FastAPI app
|
| 13 |
app = FastAPI()
|
| 14 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 15 |
# Define class labels
|
| 16 |
class_names = [
|
| 17 |
'Emergency & Accident Unit', 'Heart Clinic',
|
|
|
|
| 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 |
# 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',
|