Spaces:
				
			
			
	
			
			
		Runtime error
		
	
	
	
			
			
	
	
	
	
		
		
		Runtime error
		
	| import os | |
| import uuid | |
| import joblib | |
| import json | |
| import gradio as gr | |
| import pandas as pd | |
| from huggingface_hub import CommitScheduler | |
| from pathlib import Path | |
| import pandas as pd | |
| import numpy as np | |
| import matplotlib.pyplot as plt | |
| import seaborn as sns | |
| from warnings import filterwarnings | |
| filterwarnings('ignore') | |
| log_file = Path("logs/") / f"data_{uuid.uuid4()}.json" | |
| log_folder = log_file.parent | |
| scheduler = CommitScheduler( | |
| repo_id="machine-failure-logs", | |
| repo_type="dataset", | |
| folder_path=log_folder, | |
| path_in_repo="data", | |
| every=2 | |
| ) | |
| health_status_predictor = joblib.load('model.joblib') | |
| Latitude = gr.Number(label='Latitude') | |
| Longitude = gr.Number(label='Longitude') | |
| DBH = gr.Number(label='DBH') | |
| Tree_Height = gr.Number(label='Tree_Height') | |
| Crown_Width_North_South = gr.Number(label='Crown_Width_North_South') | |
| Crown_Width_East_West = gr.Number(label='Crown_Width_East_West') | |
| Slope = gr.Number(label='Slope') | |
| Elevation = gr.Number(label='Elevation') | |
| Temperature = gr.Number(label='Temperature') | |
| Humidity = gr.Number(label='Humidity') | |
| Soil_TN = gr.Number(label='Soil_TN') | |
| Soil_TP = gr.Number(label='Soil_TP') | |
| Soil_AP = gr.Number(label='Soil_AP') | |
| Soil_AN = gr.Number(label='Soil_AN') | |
| Menhinick_Index = gr.Number(label='Menhinick_Index') | |
| Gleason_Index = gr.Number(label='Gleason_Index') | |
| Fire_Risk_Index = gr.Number(label='Fire_Risk_Index') | |
| model_output = gr.Label(label="Health Status") | |
| def predict_health_status(Latitude, Longitude, DBH, Tree_Height, Crown_Width_North_South, Crown_Width_East_West, Slope, Elevation, Temperature, Humidity, Soil_TN, Soil_TP, Soil_AP, Soil_AN, Menhinick_Index, Gleason_Index, Fire_Risk_Index): | |
| sample = { | |
| 'Latitude': Latitude, | |
| 'Longitude': Longitude, | |
| 'DBH': DBH, | |
| 'Tree_Height': Tree_Height, | |
| 'Crown_Width_North_South': Crown_Width_North_South, | |
| 'Crown_Width_East_West': Crown_Width_East_West, | |
| 'Slope': Slope, | |
| 'Elevation': Elevation, | |
| 'Temperature': Temperature, | |
| 'Humidity': Humidity, | |
| 'Soil_TN': Soil_TN, | |
| 'Soil_TP': Soil_TP, | |
| 'Soil_AP': Soil_AP, | |
| 'Soil_AN': Soil_AN, | |
| 'Menhinick_Index': Menhinick_Index, | |
| 'Gleason_Index': Gleason_Index. | |
| 'Fire_Risk_Index': Fire_Risk_Index | |
| } | |
| data_point = pd.DataFrame([sample]) | |
| prediction = health_status_predictor.predict(data_point).tolist() | |
| with scheduler.lock: | |
| with log_file.open("a") as f: | |
| f.write(json.dumps( | |
| { | |
| 'Latitude': Latitude, | |
| 'Longitude': Longitude, | |
| 'DBH': DBH, | |
| 'Tree_Height': Tree_Height, | |
| 'Crown_Width_North_South': Crown_Width_North_South, | |
| 'Crown_Width_East_West': Crown_Width_East_West, | |
| 'Slope': Slope, | |
| 'Elevation': Elevation, | |
| 'Temperature': Temperature, | |
| 'Humidity': Humidity, | |
| 'Soil_TN': Soil_TN, | |
| 'Soil_TP': Soil_TP, | |
| 'Soil_AP': Soil_AP, | |
| 'Soil_AN': Soil_AN, | |
| 'Menhinick_Index': Menhinick_Index, | |
| 'Gleason_Index': Gleason_Index, | |
| 'Fire_Risk_Index': Fire_Risk_Index, | |
| 'prediction': prediction[0] | |
| } | |
| )) | |
| f.write("\n") | |
| return prediction[0] | |
| demo = gr.Interface( | |
| fn=predict_health_status, | |
| inputs=[Latitude, Longitude, DBH, Tree_Height, Crown_Width_North_South, Crown_Width_East_West, Slope, Elevation, Temperature, Humidity, Soil_TN, Soil_TP, Soil_AP, Soil_AN, Menhinick_Index, Gleason_Index, Fire_Risk_Index], | |
| outputs=model_output, | |
| title="Health Status Predictor", | |
| description="This API allows you to predict the health status of a Tree", | |
| allow_flagging="auto", | |
| concurrency_limit=8 | |
| ) | |
| demo.queue() | |
| demo.launch(share=False) |