WesLemon/SWENG7
0
1import gradio as gr2 3from vega_datasets import data4 5cars = data.cars()6iris = data.iris()7 8def metrics(dataset):9 if dataset == "iris":10 return gr.ScatterPlot.update(11 value=iris,12 x="petalWidth",13 y="petalLength",14 color="species",15 title="Iris Dataset",16 color_legend_title="Species",17 x_title="Petal Width",18 y_title="Petal Length",19 tooltip=["petalWidth", "petalLength", "species"],20 caption="",21 )22 else:23 return [gr.ScatterPlot.update(24 value=cars,25 x="Horsepower",26 y="Miles_per_Gallon",27 color="Origin",28 tooltip="Name",29 title="ROC Curve",30 y_title="False Positive Rate",31 x_title="True Positive Rate",32 color_legend_title="Origin of Car",33 caption="ROC Curve of Model",34 ), gr.DataFrame.update(35 value=[["Predicted Positive",1,0],["Predicted Negative",0,1]], 36 max_rows=3,37 max_cols=3,38 label="Confusion Matrix",39 show_label=True)]40 41 42with gr.Blocks() as plots:43 with gr.Row():44 with gr.Column():45 dataset = gr.Dropdown(choices=["ROC", "iris"], value="ROC")46 with gr.Row():47 with gr.Column():48 plot = gr.ScatterPlot(show_label=False).style(container=True)49 with gr.Column():50 matrix = gr.Dataframe(headers=["", "Actually Positive", "Actually Negative"],show_label=False).style(container=True)51 dataset.change(metrics, inputs=dataset, outputs=plot)52 plots.load(fn=metrics, inputs=dataset, outputs=[plot,matrix])53 54if __name__ == "__main__":55 plots.launch()