Spaces:
Sleeping
Sleeping
Commit ·
0b26f08
1
Parent(s): b7f6164
please work
Browse files- .gitignore +1 -0
- app.py +32 -4
- config.py +11 -0
.gitignore
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
__pycache__/
|
app.py
CHANGED
|
@@ -1,11 +1,39 @@
|
|
| 1 |
import gradio as gr
|
|
|
|
| 2 |
|
|
|
|
| 3 |
|
| 4 |
-
def greet(name):
|
| 5 |
-
return "Hello " + name + "!"
|
| 6 |
|
|
|
|
|
|
|
|
|
|
| 7 |
|
| 8 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 9 |
|
| 10 |
if __name__ == "__main__":
|
| 11 |
-
demo.launch(share=True,show_api=False)
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
+
import joblib
|
| 3 |
|
| 4 |
+
import config
|
| 5 |
|
|
|
|
|
|
|
| 6 |
|
| 7 |
+
def update(target_col, model_name):
|
| 8 |
+
if not target_col:
|
| 9 |
+
raise gr.Error("Please select a target column and a model")
|
| 10 |
|
| 11 |
+
clf = joblib.load("models/lr_undersampling_OfficerRace_Asian.pkl")
|
| 12 |
+
return f"Welcome to Gradio, {target_col}! Your model is {str(clf)}"
|
| 13 |
+
|
| 14 |
+
|
| 15 |
+
with gr.Blocks() as demo:
|
| 16 |
+
def available_models(target_column_name):
|
| 17 |
+
print(target_column_name, config.available_models[target_column_name])
|
| 18 |
+
updated_models_dropdown = gr.Dropdown(choices=config.available_models[target_column_name],
|
| 19 |
+
value=config.available_models[target_column_name][0],
|
| 20 |
+
multiselect=False,
|
| 21 |
+
label=config.model_label)
|
| 22 |
+
return updated_models_dropdown
|
| 23 |
+
|
| 24 |
+
|
| 25 |
+
gr.Markdown("Start typing below and then click **Run** to see the output.")
|
| 26 |
+
with gr.Row():
|
| 27 |
+
target_column_dropdown = gr.Dropdown(choices=config.target_columns,
|
| 28 |
+
multiselect=False,
|
| 29 |
+
label=config.target_label)
|
| 30 |
+
model_dropdown = gr.Dropdown(choices=[],
|
| 31 |
+
multiselect=False,
|
| 32 |
+
label=config.model_label)
|
| 33 |
+
target_column_dropdown.input(available_models, target_column_dropdown, model_dropdown)
|
| 34 |
+
out = gr.Textbox()
|
| 35 |
+
btn = gr.Button("Predict")
|
| 36 |
+
btn.click(fn=update, inputs=[target_column_dropdown, model_dropdown], outputs=out)
|
| 37 |
|
| 38 |
if __name__ == "__main__":
|
| 39 |
+
demo.launch(share=True, show_api=False)
|
config.py
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# values
|
| 2 |
+
target_columns = ["Officer Race", "Officer Gender", "Penalty"]
|
| 3 |
+
available_models = {
|
| 4 |
+
"Officer Race": ["A", "B", "C"],
|
| 5 |
+
"Officer Gender": ["D", "E", "F"],
|
| 6 |
+
"Penalty": ["G", "H", "I"]
|
| 7 |
+
}
|
| 8 |
+
|
| 9 |
+
# labels
|
| 10 |
+
model_label = "Choose a model"
|
| 11 |
+
target_label = "What do you want to predict?"
|