Update app.py
Browse files
app.py
CHANGED
@@ -7,6 +7,7 @@ from langchain_openai import ChatOpenAI
|
|
7 |
from langchain_experimental.agents.agent_toolkits import create_pandas_dataframe_agent
|
8 |
from langchain.agents.agent_types import AgentType
|
9 |
from langchain_google_genai import ChatGoogleGenerativeAI
|
|
|
10 |
|
11 |
def explain_df(query, df):
|
12 |
agent = create_pandas_dataframe_agent(
|
@@ -82,6 +83,7 @@ numeric_columns = df.select_dtypes(include=[np.number]).columns
|
|
82 |
numeric_columns = numeric_columns.drop('model_physical_size')
|
83 |
df[numeric_columns] = (df[numeric_columns]*100).round(2)
|
84 |
df['model_physical_size'] = df['model_physical_size'].round(2)
|
|
|
85 |
full_df = df.merge(perf_df, left_on='hf_name', right_on='hf_name', how='left')
|
86 |
|
87 |
with gr.Blocks() as demo:
|
@@ -102,21 +104,45 @@ with gr.Blocks() as demo:
|
|
102 |
latency_line_plot = gr.Plot(label="Latency vs Average Accuracy")
|
103 |
with gr.Row():
|
104 |
data_table = gr.Dataframe(value=df, label="Result Table")
|
|
|
105 |
def update_outputs(selected_tasks):
|
106 |
if not selected_tasks:
|
107 |
return df[['model', 'precision']], None, None
|
108 |
filtered_df = df[['model', 'precision', 'model_physical_size','hf_name'] + selected_tasks]
|
109 |
# average accuracy of selected tasks
|
110 |
filtered_df['avg_accuracy'] = filtered_df[selected_tasks].mean(axis=1)
|
|
|
111 |
bar_fig = px.bar(filtered_df, x='model', y='avg_accuracy', color='precision', barmode='group')
|
112 |
line_fig = px.line(filtered_df, x='model_physical_size', y='avg_accuracy', color='model', symbol='precision')
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
113 |
# set title of bar_fig
|
114 |
bar_fig.update_layout(title=f'tasks: {", ".join(selected_tasks)}')
|
115 |
line_fig.update_layout(title=f'tasks: {", ".join(selected_tasks)}')
|
116 |
with_perf_df = filtered_df.merge(perf_df, left_on='hf_name', right_on='hf_name', how='left')
|
117 |
throughput_line_fig = px.line(with_perf_df, x='output_throughput', y='avg_accuracy', color='model', symbol='precision')
|
118 |
latency_line_fig = px.line(with_perf_df, x="avg_e2e_latency", y='avg_accuracy', color='model', symbol='precision')
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
119 |
return with_perf_df, bar_fig, line_fig, throughput_line_fig, latency_line_fig
|
|
|
120 |
selected_tasks.change(
|
121 |
fn=update_outputs,
|
122 |
inputs=selected_tasks,
|
|
|
7 |
from langchain_experimental.agents.agent_toolkits import create_pandas_dataframe_agent
|
8 |
from langchain.agents.agent_types import AgentType
|
9 |
from langchain_google_genai import ChatGoogleGenerativeAI
|
10 |
+
import plotly.graph_objects as go
|
11 |
|
12 |
def explain_df(query, df):
|
13 |
agent = create_pandas_dataframe_agent(
|
|
|
83 |
numeric_columns = numeric_columns.drop('model_physical_size')
|
84 |
df[numeric_columns] = (df[numeric_columns]*100).round(2)
|
85 |
df['model_physical_size'] = df['model_physical_size'].round(2)
|
86 |
+
|
87 |
full_df = df.merge(perf_df, left_on='hf_name', right_on='hf_name', how='left')
|
88 |
|
89 |
with gr.Blocks() as demo:
|
|
|
104 |
latency_line_plot = gr.Plot(label="Latency vs Average Accuracy")
|
105 |
with gr.Row():
|
106 |
data_table = gr.Dataframe(value=df, label="Result Table")
|
107 |
+
|
108 |
def update_outputs(selected_tasks):
|
109 |
if not selected_tasks:
|
110 |
return df[['model', 'precision']], None, None
|
111 |
filtered_df = df[['model', 'precision', 'model_physical_size','hf_name'] + selected_tasks]
|
112 |
# average accuracy of selected tasks
|
113 |
filtered_df['avg_accuracy'] = filtered_df[selected_tasks].mean(axis=1)
|
114 |
+
|
115 |
bar_fig = px.bar(filtered_df, x='model', y='avg_accuracy', color='precision', barmode='group')
|
116 |
line_fig = px.line(filtered_df, x='model_physical_size', y='avg_accuracy', color='model', symbol='precision')
|
117 |
+
pareto_df = filtered_df.sort_values('model_physical_size')
|
118 |
+
pareto_df = pareto_df.loc[pareto_df['avg_accuracy'].cummax().drop_duplicates().index]
|
119 |
+
# Add Pareto frontier to line_plot
|
120 |
+
line_fig.add_trace(go.Scatter(
|
121 |
+
x=pareto_df['model_physical_size'],
|
122 |
+
y=pareto_df['avg_accuracy'],
|
123 |
+
mode='lines+markers',
|
124 |
+
name='Pareto Frontier'
|
125 |
+
))
|
126 |
+
|
127 |
# set title of bar_fig
|
128 |
bar_fig.update_layout(title=f'tasks: {", ".join(selected_tasks)}')
|
129 |
line_fig.update_layout(title=f'tasks: {", ".join(selected_tasks)}')
|
130 |
with_perf_df = filtered_df.merge(perf_df, left_on='hf_name', right_on='hf_name', how='left')
|
131 |
throughput_line_fig = px.line(with_perf_df, x='output_throughput', y='avg_accuracy', color='model', symbol='precision')
|
132 |
latency_line_fig = px.line(with_perf_df, x="avg_e2e_latency", y='avg_accuracy', color='model', symbol='precision')
|
133 |
+
|
134 |
+
pareto_df = with_perf_df.sort_values('avg_e2e_latency')
|
135 |
+
pareto_df = pareto_df.loc[pareto_df['avg_accuracy'].cummax().drop_duplicates().index]
|
136 |
+
|
137 |
+
latency_line_fig.add_trace(go.Scatter(
|
138 |
+
x=pareto_df['avg_e2e_latency'],
|
139 |
+
y=pareto_df['avg_accuracy'],
|
140 |
+
mode='lines+markers',
|
141 |
+
name='Pareto Frontier'
|
142 |
+
))
|
143 |
+
print(with_perf_df)
|
144 |
return with_perf_df, bar_fig, line_fig, throughput_line_fig, latency_line_fig
|
145 |
+
|
146 |
selected_tasks.change(
|
147 |
fn=update_outputs,
|
148 |
inputs=selected_tasks,
|