Spaces:
Sleeping
Sleeping
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] # rfc.predict() gives data in a nested list. So selecting list at 0th index | |
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 f"{class_name}\n\nThank You For Using Our Model 😊 !!" | |
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", | |
title="<span id=title-first>Aqua</span> <span id=title-second>💧Alert</span> <br> " | |
"<span id=title-desc> a ML Model which can predict contaminants present in the waste water</span>", | |
description="<span id=desc-info> <br>★ Some examples are present at the bottom for your convenience <a id=a-tag " | |
"href=https://theabhishek.me/Aqua-Alert/ target=_blank>(visit website)</a> </span>", | |
theme=gr.themes.Soft(), | |
css=""" | |
.gradio-container {background-color: #daeefe} | |
#tbox { background-color : teal !important; } | |
#tbox textarea {background-color: black; font-size : 15px; color : white; font-weight : bold; !important;} | |
#title-first {color:#034782; font-size : 50px; border-style: solid; border-color: black !important;} | |
#title-second {color:#034782; font-size : 50px !important;} | |
#title-desc {color : black; text-align: center; font-size : 15px !important;} | |
#title-desc:hover {background-color : yellow !important;} | |
#desc-info {font-size : 12px; color: black; font-weight : bold; text-align: center !important;} | |
#a-tag { color : black !important;} | |
#a-tag:hover { text-decoration : none !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], | |
[1506, 12770, 17221, -10802, 2017,-1800, 7413,-2530, 5279, -2600, 3073,-3492 ], | |
[3044, 15856, 20114, -5594, 6915, -2732, 15199, -2292, 14491, -2392, 16643, -1362] | |
] | |
) | |
demo.launch(inline=False) | |