Spaces:
Sleeping
Sleeping
Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,63 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import streamlit as st
|
| 2 |
+
import json
|
| 3 |
+
import pandas as pd
|
| 4 |
+
import plotly.express as px
|
| 5 |
+
|
| 6 |
+
# Define categories
|
| 7 |
+
CATEGORIES = ["Writing", "Roleplay", "Reasoning", "Math", "Coding", "Extraction", "STEM", "Humanities"]
|
| 8 |
+
|
| 9 |
+
# Load and process the single model data
|
| 10 |
+
@st.cache(allow_output_mutation=True)
|
| 11 |
+
def get_model_df():
|
| 12 |
+
q2result = []
|
| 13 |
+
# Replace "gpt-4_single.jsonl" with the actual path to your JSONL file
|
| 14 |
+
with open("gpt-4_single.jsonl", "r") as fin:
|
| 15 |
+
for line in fin:
|
| 16 |
+
obj = json.loads(line)
|
| 17 |
+
obj["category"] = CATEGORIES[(obj["question_id"] - 81) // 10]
|
| 18 |
+
q2result.append(obj)
|
| 19 |
+
df = pd.DataFrame(q2result)
|
| 20 |
+
return df
|
| 21 |
+
|
| 22 |
+
# Placeholder for the pair model data function
|
| 23 |
+
# Adapt this function based on how your "gpt-4_pair.jsonl" is structured
|
| 24 |
+
@st.cache(allow_output_mutation=True)
|
| 25 |
+
def get_model_df_pair():
|
| 26 |
+
# Implement similar to get_model_df if you have pair data
|
| 27 |
+
return pd.DataFrame([]) # Placeholder
|
| 28 |
+
|
| 29 |
+
df = get_model_df()
|
| 30 |
+
df_pair = get_model_df_pair()
|
| 31 |
+
|
| 32 |
+
# Streamlit app starts here
|
| 33 |
+
st.title('Model Performance Visualization')
|
| 34 |
+
|
| 35 |
+
# Select models to display
|
| 36 |
+
all_models = df["model"].unique()
|
| 37 |
+
selected_models = st.multiselect('Select Models', all_models, default=all_models[:3])
|
| 38 |
+
|
| 39 |
+
# Main app logic
|
| 40 |
+
if selected_models:
|
| 41 |
+
scores_all = []
|
| 42 |
+
for model in selected_models:
|
| 43 |
+
for cat in CATEGORIES:
|
| 44 |
+
res = df[(df["category"] == cat) & (df["model"] == model) & (df["score"] >= 0)]
|
| 45 |
+
score = res["score"].mean()
|
| 46 |
+
scores_all.append({"model": model, "category": cat, "score": score})
|
| 47 |
+
|
| 48 |
+
df_score = pd.DataFrame(scores_all)
|
| 49 |
+
|
| 50 |
+
# Renaming models for better visualization
|
| 51 |
+
rename_map = {
|
| 52 |
+
# Define your renaming map here, if needed
|
| 53 |
+
}
|
| 54 |
+
df_score.replace(rename_map, inplace=True)
|
| 55 |
+
|
| 56 |
+
# Generate the radial graph
|
| 57 |
+
fig = px.line_polar(df_score, r='score', theta='category', line_close=True,
|
| 58 |
+
category_orders={"category": CATEGORIES}, color='model', markers=True)
|
| 59 |
+
|
| 60 |
+
# Display the Plotly figure in Streamlit
|
| 61 |
+
st.plotly_chart(fig)
|
| 62 |
+
|
| 63 |
+
st.caption("Note: Make sure to replace placeholder paths with actual paths to your JSONL files.")
|