import os import pandas as pd from sklearn.ensemble import RandomForestClassifier from sklearn.model_selection import train_test_split import gradio as gr current_dir = os.path.dirname(os.path.realpath(__file__)) data = pd.read_csv(os.path.join(current_dir, "data.csv")) X_all = data.drop(["targets"], axis=1) y_all = data["targets"] num_test = 0.20 X_train, X_test, y_train, y_test = train_test_split( X_all, y_all, test_size=num_test, random_state=23 ) clf = RandomForestClassifier() clf.fit(X_train, y_train) predictions = clf.predict(X_test) def predict_survival(densites, diametres): df = pd.DataFrame.from_dict( { "densites": [densites], "diametres": [diametres] } ) pred = clf.predict_proba(df)[0] return {"No": float(pred[0]), "Yes": float(pred[1])} demo = gr.Interface( predict_survival, [ gr.Number(value=0), gr.Number(value=0) ], "label", examples=[ [700, 5] ], live=True, ) if __name__ == "__main__": demo.launch(share=True)