Spaces:
Running
Running
Joschka Strueber
commited on
Commit
·
874e761
1
Parent(s):
30bd486
[Add, Ref] matplotlib test, random test value for sim
Browse files- app.py +36 -0
- src/similarity.py +5 -0
app.py
CHANGED
|
@@ -1,7 +1,38 @@
|
|
| 1 |
import gradio as gr
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 2 |
from src.dataloading import get_leaderboard_models_cached, get_leaderboard_datasets
|
| 3 |
from src.similarity import compute_similarity
|
| 4 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 5 |
def validate_inputs(selected_model_a, selected_model_b, selected_dataset):
|
| 6 |
if not selected_model_a:
|
| 7 |
raise gr.Error("Please select Model A!")
|
|
@@ -66,5 +97,10 @@ with gr.Blocks(title="LLM Similarity Analyzer") as demo:
|
|
| 66 |
outputs=[model_a_dropdown, model_b_dropdown, dataset_dropdown, similarity_output]
|
| 67 |
)
|
| 68 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 69 |
if __name__ == "__main__":
|
| 70 |
demo.launch()
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
+
import matplotlib.pyplot as plt
|
| 3 |
+
import numpy as np
|
| 4 |
+
from io import BytesIO
|
| 5 |
+
from PIL import Image
|
| 6 |
+
|
| 7 |
from src.dataloading import get_leaderboard_models_cached, get_leaderboard_datasets
|
| 8 |
from src.similarity import compute_similarity
|
| 9 |
|
| 10 |
+
# Set the backend to 'Agg' for non-GUI environments (optional)
|
| 11 |
+
import matplotlib
|
| 12 |
+
matplotlib.use('Agg')
|
| 13 |
+
|
| 14 |
+
|
| 15 |
+
def generate_plot():
|
| 16 |
+
# Generate data
|
| 17 |
+
x = np.linspace(0, 10, 100)
|
| 18 |
+
y = np.sin(x)
|
| 19 |
+
|
| 20 |
+
# Create figure
|
| 21 |
+
fig, ax = plt.subplots()
|
| 22 |
+
ax.plot(x, y)
|
| 23 |
+
ax.set_title("Sine Wave")
|
| 24 |
+
|
| 25 |
+
# Save figure to a BytesIO buffer
|
| 26 |
+
buf = BytesIO()
|
| 27 |
+
fig.savefig(buf, format="png", bbox_inches="tight", facecolor="white", dpi=100)
|
| 28 |
+
plt.close(fig) # Close the figure to free memory
|
| 29 |
+
|
| 30 |
+
# Convert buffer to PIL Image
|
| 31 |
+
buf.seek(0)
|
| 32 |
+
img = Image.open(buf).convert("RGB")
|
| 33 |
+
return img
|
| 34 |
+
|
| 35 |
+
|
| 36 |
def validate_inputs(selected_model_a, selected_model_b, selected_dataset):
|
| 37 |
if not selected_model_a:
|
| 38 |
raise gr.Error("Please select Model A!")
|
|
|
|
| 97 |
outputs=[model_a_dropdown, model_b_dropdown, dataset_dropdown, similarity_output]
|
| 98 |
)
|
| 99 |
|
| 100 |
+
gr.Markdown("## Matplotlib Plot in Gradio")
|
| 101 |
+
plot_button = gr.Button("Generate Plot")
|
| 102 |
+
plot_output = gr.Image(label="Sine Wave Plot")
|
| 103 |
+
plot_button.click(fn=generate_plot, outputs=plot_output)
|
| 104 |
+
|
| 105 |
if __name__ == "__main__":
|
| 106 |
demo.launch()
|
src/similarity.py
CHANGED
|
@@ -1,8 +1,10 @@
|
|
| 1 |
from src.dataloading import load_run_data
|
| 2 |
from lmsim.metrics import Kappa_p
|
|
|
|
| 3 |
|
| 4 |
|
| 5 |
def compute_similarity(selected_model_a, selected_model_b, selected_dataset):
|
|
|
|
| 6 |
probs_a, gt_a = load_run_data(selected_model_a, selected_dataset)
|
| 7 |
probs_b, gt_b = load_run_data(selected_model_b, selected_dataset)
|
| 8 |
|
|
@@ -21,5 +23,8 @@ def compute_similarity(selected_model_a, selected_model_b, selected_dataset):
|
|
| 21 |
# Placeholder similarity value
|
| 22 |
kappa_p = Kappa_p()
|
| 23 |
similarity = kappa_p.compute_k(output_a, output_b, gt)
|
|
|
|
|
|
|
|
|
|
| 24 |
|
| 25 |
return similarity
|
|
|
|
| 1 |
from src.dataloading import load_run_data
|
| 2 |
from lmsim.metrics import Kappa_p
|
| 3 |
+
import random
|
| 4 |
|
| 5 |
|
| 6 |
def compute_similarity(selected_model_a, selected_model_b, selected_dataset):
|
| 7 |
+
"""
|
| 8 |
probs_a, gt_a = load_run_data(selected_model_a, selected_dataset)
|
| 9 |
probs_b, gt_b = load_run_data(selected_model_b, selected_dataset)
|
| 10 |
|
|
|
|
| 23 |
# Placeholder similarity value
|
| 24 |
kappa_p = Kappa_p()
|
| 25 |
similarity = kappa_p.compute_k(output_a, output_b, gt)
|
| 26 |
+
"""
|
| 27 |
+
|
| 28 |
+
similarity = random.random()
|
| 29 |
|
| 30 |
return similarity
|