import gradio as gr import pandas as pd from sklearn.model_selection import train_test_split from sklearn.ensemble import RandomForestClassifier #Loading the dataset df = pd.read_csv('data/one_data.csv') x_train, x_test, y_train, y_test = train_test_split(df.drop('CLASS', axis=1), df['CLASS'], test_size=0.2, random_state=42) # Create a random forest classifier rfc = RandomForestClassifier() # Training the model using the training data rfc.fit(x_train, y_train) # Predicting the Loan Approval Status #rfc_pred = rfc.predict(x_test) def ml_model(a, b, c, d, e, f, g, h, i, j, k, l): test_data = [[a, b, c, d, e, f, g, h, i, j, k, l]] rfc_pred = rfc.predict(test_data)[0] dict = { 0: "Acetic Acid", 1: "Acetone", 2: "Ammonia", 3: "Ethanol", 4: "Formic Acid", 5: "Hydrochloric Acid", 6: "Hydrogen Peroxide", 7: "Phosphoric Acid", 8: "Sodium Hypochlorite", 9: "Sulphuric Acid", 10: "Waste water" } class_name = f"Class : {dict[rfc_pred]}" return class_name, "Thank You" demo = gr.Interface( fn=ml_model, inputs=[ gr.Textbox(label="PLATINUM_78kHz_RESISTANCE", placeholder="Enter data here..", elem_id="tbox", type='text'), gr.Textbox(label="GOLD_78kHz_RESISTANCE", placeholder="Enter data here..", elem_id="tbox", type='text'), gr.Textbox(label="PLATINUM_200Hz_RESISTANCE", placeholder="Enter data here..", elem_id="tbox", type='text'), gr.Textbox(label="PLATINUM_200Hz_CAPACITANCE", placeholder="Enter data here..", elem_id="tbox", type='text'), gr.Textbox(label="GOLD_200Hz_RESISTANCE", placeholder="Enter data here..", elem_id="tbox", type='text'), gr.Textbox(label="GOLD_200Hz_CAPACITANCE", placeholder="Enter data here..", elem_id="tbox", type='text'), gr.Textbox(label="COPPER_200Hz_RESISTANCE", placeholder="Enter data here..", elem_id="tbox", type='text'), gr.Textbox(label="COPPER_200Hz_CAPACITANCE", placeholder="Enter data here..", elem_id="tbox", type='text'), gr.Textbox(label="SILVER_200Hz_RESISTANCE", placeholder="Enter data here..", elem_id="tbox", type='text'), gr.Textbox(label="SILVER_200Hz_CAPACITANCE", placeholder="Enter data here..", elem_id="tbox", type='text'), gr.Textbox(label="NICKEL_200Hz_RESISTANCE", placeholder="Enter data here..", elem_id="tbox", type='text'), gr.Textbox(label="NICKEL_200Hz_CAPACITANCE", placeholder="Enter data here..", elem_id="tbox", type='text'), ], outputs=["text", "text"], title="Aqua Alert", description="
a ML Model which can predict contaminants present " "in the waste water
", theme=gr.themes.Soft(), css=""" #tbox { color : black; width: 100 !important; } #tbox textarea {background-color: white; font-size : 15px; color : black; font-weight : bold; !important;} """, examples=[ [2292.000, 13980.000, 1206.0000, -523.000, 4698.000, -3925.0000, 6757.0000, -3263.0000, 11269.000, -3596.000, 14611.000, -1492.000], [3506, 16706, 22694, -4568, 14771, -2786, 15861, -1989, 15082, -2095, 17293, -133], [3230, 16109, 19895, -6970, 7621, -3032, 14481, -2957, 13919, -3001, 16518, -2134] ] ) demo.launch(inbrowser=True)