Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,54 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
import joblib
|
| 3 |
+
import numpy as np
|
| 4 |
+
from huggingface_hub import hf_hub_download
|
| 5 |
+
|
| 6 |
+
# Function to load the model from Hugging Face Hub
|
| 7 |
+
def load_model():
|
| 8 |
+
# Download the model from Hugging Face Hub
|
| 9 |
+
model_file = hf_hub_download("your_username/burnout-prediction-model", "burnout_model.pkl")
|
| 10 |
+
model = joblib.load(model_file)
|
| 11 |
+
return model
|
| 12 |
+
|
| 13 |
+
# Load the model
|
| 14 |
+
model = load_model()
|
| 15 |
+
|
| 16 |
+
# Function to make prediction
|
| 17 |
+
def predict_burnout(input_features):
|
| 18 |
+
# Ensure the input data is a numpy array with shape (1, -1)
|
| 19 |
+
input_data = np.array(input_features).reshape(1, -1)
|
| 20 |
+
|
| 21 |
+
# Make prediction
|
| 22 |
+
burnout_percentage = model.predict(input_data)
|
| 23 |
+
|
| 24 |
+
return f"Predicted Burnout Percentage: {burnout_percentage[0]:.2f}%"
|
| 25 |
+
|
| 26 |
+
# Create Gradio interface
|
| 27 |
+
def create_interface():
|
| 28 |
+
# Define the input and output format for the Gradio interface
|
| 29 |
+
input_interface = gr.inputs.Dataframe(
|
| 30 |
+
headers=["Feature 1", "Feature 2", "Feature 3", ..., "Feature 90"],
|
| 31 |
+
col_count=1,
|
| 32 |
+
row_count=90,
|
| 33 |
+
type="number",
|
| 34 |
+
label="Enter Last 90 Days Data"
|
| 35 |
+
)
|
| 36 |
+
|
| 37 |
+
output_interface = gr.outputs.Textbox(label="Predicted Burnout")
|
| 38 |
+
|
| 39 |
+
# Create the Gradio app
|
| 40 |
+
interface = gr.Interface(
|
| 41 |
+
fn=predict_burnout,
|
| 42 |
+
inputs=input_interface,
|
| 43 |
+
outputs=output_interface,
|
| 44 |
+
live=True,
|
| 45 |
+
title="Burnout Prediction Model",
|
| 46 |
+
description="Enter the last 90 days of data and get the predicted burnout percentage."
|
| 47 |
+
)
|
| 48 |
+
|
| 49 |
+
return interface
|
| 50 |
+
|
| 51 |
+
# Launch the Gradio app
|
| 52 |
+
if __name__ == "__main__":
|
| 53 |
+
interface = create_interface()
|
| 54 |
+
interface.launch()
|