Spaces:
Build error
Build error
Update app.py
Browse files
app.py
CHANGED
|
@@ -4,34 +4,31 @@ import matplotlib.pyplot as plt
|
|
| 4 |
import io
|
| 5 |
from PIL import Image
|
| 6 |
|
| 7 |
-
#
|
| 8 |
metrics = {
|
| 9 |
"Классификация обращений": {
|
| 10 |
-
"ChatGPT": {"Точность":
|
| 11 |
-
"GigaChat": {"Точность":
|
| 12 |
-
"DeepSeek": {"Точность":
|
| 13 |
},
|
| 14 |
"Антифрод": {
|
| 15 |
-
"ChatGPT": {"Точность":
|
| 16 |
-
"GigaChat": {"Точность":
|
| 17 |
-
"DeepSeek": {"Точность":
|
| 18 |
},
|
| 19 |
"Генерация SQL": {
|
| 20 |
-
"ChatGPT": {"Точность":
|
| 21 |
-
"GigaChat": {"Точность":
|
| 22 |
-
"DeepSeek": {"Точность":
|
| 23 |
}
|
| 24 |
}
|
| 25 |
|
| 26 |
-
# Вспомогательная функция: сохраняем matplotlib-plot как изображение
|
| 27 |
def fig_to_image(fig):
|
| 28 |
buf = io.BytesIO()
|
| 29 |
fig.savefig(buf, format="png", bbox_inches="tight", dpi=150)
|
| 30 |
buf.seek(0)
|
| 31 |
-
|
| 32 |
-
return img
|
| 33 |
|
| 34 |
-
# Главная функция обновления
|
| 35 |
def update(task, selected_criteria):
|
| 36 |
models = ["ChatGPT", "GigaChat", "DeepSeek"]
|
| 37 |
cards = []
|
|
@@ -42,8 +39,8 @@ def update(task, selected_criteria):
|
|
| 42 |
items_html = ""
|
| 43 |
for crit in criteria:
|
| 44 |
score = vals[crit]
|
| 45 |
-
desc = "Высокая" if score
|
| 46 |
-
items_html += f"<li>{crit}: {score}/
|
| 47 |
card_html = f"""
|
| 48 |
<div class="card dark-card">
|
| 49 |
<h3>{model}</h3>
|
|
@@ -56,21 +53,21 @@ def update(task, selected_criteria):
|
|
| 56 |
x = np.arange(len(models))
|
| 57 |
width = 0.8 / len(criteria)
|
| 58 |
|
| 59 |
-
# График 1:
|
| 60 |
fig1, ax1 = plt.subplots(figsize=(5, 3))
|
| 61 |
for i, crit in enumerate(criteria):
|
| 62 |
values = [metrics[task][m][crit] for m in models]
|
| 63 |
bars = ax1.bar(x + i * width, values, width, label=crit)
|
| 64 |
for bar in bars:
|
| 65 |
height = bar.get_height()
|
| 66 |
-
ax1.annotate(f'{height}', xy=(bar.get_x() + bar.get_width() / 2, height + 0.
|
| 67 |
-
ha='center', fontsize=
|
| 68 |
ax1.set_xticks(x + width*(len(criteria)-1)/2)
|
| 69 |
ax1.set_xticklabels(models)
|
| 70 |
-
ax1.set_ylim(0,
|
| 71 |
-
ax1.set_ylabel("Оценка (
|
| 72 |
ax1.set_title(f"Сравнение моделей по критериям\nЗадача: {task}")
|
| 73 |
-
ax1.legend(fontsize=7)
|
| 74 |
ax1.grid(axis='y', linestyle='--', alpha=0.3)
|
| 75 |
fig1.patch.set_facecolor('#1e1e1e')
|
| 76 |
ax1.set_facecolor('#1e1e1e')
|
|
@@ -81,7 +78,7 @@ def update(task, selected_criteria):
|
|
| 81 |
ax1.legend().get_frame().set_facecolor('#2e2e2e')
|
| 82 |
ax1.legend().get_frame().set_edgecolor('#444')
|
| 83 |
|
| 84 |
-
# График 2: средние
|
| 85 |
avg_scores = []
|
| 86 |
for model in models:
|
| 87 |
vals = metrics[task][model]
|
|
@@ -92,10 +89,10 @@ def update(task, selected_criteria):
|
|
| 92 |
bars = ax2.bar(models, avg_scores, color=['#4c78a8','#f58518','#54a24b'])
|
| 93 |
for bar in bars:
|
| 94 |
height = bar.get_height()
|
| 95 |
-
ax2.annotate(f'{height:.
|
| 96 |
-
ha='center', fontsize=
|
| 97 |
-
ax2.set_ylim(0,
|
| 98 |
-
ax2.set_ylabel("Средний балл")
|
| 99 |
ax2.set_title("Средний балл моделей")
|
| 100 |
ax2.grid(axis='y', linestyle='--', alpha=0.3)
|
| 101 |
fig2.patch.set_facecolor('#1e1e1e')
|
|
@@ -105,7 +102,7 @@ def update(task, selected_criteria):
|
|
| 105 |
ax2.xaxis.label.set_color('white')
|
| 106 |
ax2.title.set_color('white')
|
| 107 |
|
| 108 |
-
# Лидер
|
| 109 |
sums = {model: sum(metrics[task][model][crit] for crit in criteria) for model in models}
|
| 110 |
leader = max(sums, key=sums.get)
|
| 111 |
result = f"📌 **Модель `{leader}` лидирует** по выбранным критериям в задаче **{task}**."
|
|
@@ -121,8 +118,8 @@ css = """
|
|
| 121 |
.card.dark-card li { margin: 4px 0; }
|
| 122 |
"""
|
| 123 |
|
| 124 |
-
#
|
| 125 |
-
with gr.Blocks(css=css
|
| 126 |
gr.Markdown("## Сравнение моделей ChatGPT, GigaChat и DeepSeek", elem_id="title")
|
| 127 |
with gr.Row():
|
| 128 |
with gr.Column(scale=2):
|
|
@@ -136,7 +133,6 @@ with gr.Blocks(css=css, theme=gr.themes.Base()) as demo:
|
|
| 136 |
chart2 = gr.Image(label="Средний балл", interactive=True)
|
| 137 |
result_md = gr.Markdown()
|
| 138 |
|
| 139 |
-
# Обновление при выборе
|
| 140 |
task_dropdown.change(update, [task_dropdown, criteria_check], [card1, card2, card3, chart1, chart2, result_md])
|
| 141 |
criteria_check.change(update, [task_dropdown, criteria_check], [card1, card2, card3, chart1, chart2, result_md])
|
| 142 |
|
|
|
|
| 4 |
import io
|
| 5 |
from PIL import Image
|
| 6 |
|
| 7 |
+
# Оценки от 1 до 5
|
| 8 |
metrics = {
|
| 9 |
"Классификация обращений": {
|
| 10 |
+
"ChatGPT": {"Точность": 5, "Интерпретируемость": 4, "Стабильность": 4, "Время отклика": 3, "Применимость": 4},
|
| 11 |
+
"GigaChat": {"Точность": 4, "Интерпретируемость": 3, "Стабильность": 4, "Время отклика": 5, "Применимость": 4},
|
| 12 |
+
"DeepSeek": {"Точность": 3, "Интерпретируемость": 4, "Стабильность": 3, "Время отклика": 4, "Применимость": 4},
|
| 13 |
},
|
| 14 |
"Антифрод": {
|
| 15 |
+
"ChatGPT": {"Точность": 4, "Интерпретируемость": 3, "Стабильность": 5, "Время отклика": 2, "Применимость": 3},
|
| 16 |
+
"GigaChat": {"Точность": 5, "Интерпретируемость": 3, "Стабильность": 4, "Время отклика": 3, "Применимость": 4},
|
| 17 |
+
"DeepSeek": {"Точность": 3, "Интерпретируемость": 2, "Стабильность": 4, "Время отклика": 5, "Применимость": 4},
|
| 18 |
},
|
| 19 |
"Генерация SQL": {
|
| 20 |
+
"ChatGPT": {"Точность": 5, "Интерпретируемость": 4, "Стабильность": 4, "Время отклика": 3, "Применимость": 4},
|
| 21 |
+
"GigaChat": {"Точность": 3, "Интерпретируемость": 3, "Стабильность": 3, "Время отклика": 4, "Применимость": 3},
|
| 22 |
+
"DeepSeek": {"Точность": 4, "Интерпретируемость": 2, "Стабильность": 5, "Время отклика": 5, "Применимость": 4},
|
| 23 |
}
|
| 24 |
}
|
| 25 |
|
|
|
|
| 26 |
def fig_to_image(fig):
|
| 27 |
buf = io.BytesIO()
|
| 28 |
fig.savefig(buf, format="png", bbox_inches="tight", dpi=150)
|
| 29 |
buf.seek(0)
|
| 30 |
+
return Image.open(buf)
|
|
|
|
| 31 |
|
|
|
|
| 32 |
def update(task, selected_criteria):
|
| 33 |
models = ["ChatGPT", "GigaChat", "DeepSeek"]
|
| 34 |
cards = []
|
|
|
|
| 39 |
items_html = ""
|
| 40 |
for crit in criteria:
|
| 41 |
score = vals[crit]
|
| 42 |
+
desc = "Высокая" if score == 5 else "Средняя" if score >= 3 else "Низкая"
|
| 43 |
+
items_html += f"<li>{crit}: {score}/5 ({desc})</li>"
|
| 44 |
card_html = f"""
|
| 45 |
<div class="card dark-card">
|
| 46 |
<h3>{model}</h3>
|
|
|
|
| 53 |
x = np.arange(len(models))
|
| 54 |
width = 0.8 / len(criteria)
|
| 55 |
|
| 56 |
+
# График 1: по критериям
|
| 57 |
fig1, ax1 = plt.subplots(figsize=(5, 3))
|
| 58 |
for i, crit in enumerate(criteria):
|
| 59 |
values = [metrics[task][m][crit] for m in models]
|
| 60 |
bars = ax1.bar(x + i * width, values, width, label=crit)
|
| 61 |
for bar in bars:
|
| 62 |
height = bar.get_height()
|
| 63 |
+
ax1.annotate(f'{height}', xy=(bar.get_x() + bar.get_width() / 2, height + 0.15),
|
| 64 |
+
ha='center', fontsize=9, color='white')
|
| 65 |
ax1.set_xticks(x + width*(len(criteria)-1)/2)
|
| 66 |
ax1.set_xticklabels(models)
|
| 67 |
+
ax1.set_ylim(0, 5.5)
|
| 68 |
+
ax1.set_ylabel("Оценка (1–5)")
|
| 69 |
ax1.set_title(f"Сравнение моделей по критериям\nЗадача: {task}")
|
| 70 |
+
ax1.legend(fontsize=7, loc='upper right')
|
| 71 |
ax1.grid(axis='y', linestyle='--', alpha=0.3)
|
| 72 |
fig1.patch.set_facecolor('#1e1e1e')
|
| 73 |
ax1.set_facecolor('#1e1e1e')
|
|
|
|
| 78 |
ax1.legend().get_frame().set_facecolor('#2e2e2e')
|
| 79 |
ax1.legend().get_frame().set_edgecolor('#444')
|
| 80 |
|
| 81 |
+
# График 2: средние баллы
|
| 82 |
avg_scores = []
|
| 83 |
for model in models:
|
| 84 |
vals = metrics[task][model]
|
|
|
|
| 89 |
bars = ax2.bar(models, avg_scores, color=['#4c78a8','#f58518','#54a24b'])
|
| 90 |
for bar in bars:
|
| 91 |
height = bar.get_height()
|
| 92 |
+
ax2.annotate(f'{height:.2f}', xy=(bar.get_x() + bar.get_width() / 2, height + 0.15),
|
| 93 |
+
ha='center', fontsize=9, color='white')
|
| 94 |
+
ax2.set_ylim(0, 5.5)
|
| 95 |
+
ax2.set_ylabel("Средний балл (1–5)")
|
| 96 |
ax2.set_title("Средний балл моделей")
|
| 97 |
ax2.grid(axis='y', linestyle='--', alpha=0.3)
|
| 98 |
fig2.patch.set_facecolor('#1e1e1e')
|
|
|
|
| 102 |
ax2.xaxis.label.set_color('white')
|
| 103 |
ax2.title.set_color('white')
|
| 104 |
|
| 105 |
+
# Лидер
|
| 106 |
sums = {model: sum(metrics[task][model][crit] for crit in criteria) for model in models}
|
| 107 |
leader = max(sums, key=sums.get)
|
| 108 |
result = f"📌 **Модель `{leader}` лидирует** по выбранным критериям в задаче **{task}**."
|
|
|
|
| 118 |
.card.dark-card li { margin: 4px 0; }
|
| 119 |
"""
|
| 120 |
|
| 121 |
+
# Gradio интерфейс
|
| 122 |
+
with gr.Blocks(css=css) as demo:
|
| 123 |
gr.Markdown("## Сравнение моделей ChatGPT, GigaChat и DeepSeek", elem_id="title")
|
| 124 |
with gr.Row():
|
| 125 |
with gr.Column(scale=2):
|
|
|
|
| 133 |
chart2 = gr.Image(label="Средний балл", interactive=True)
|
| 134 |
result_md = gr.Markdown()
|
| 135 |
|
|
|
|
| 136 |
task_dropdown.change(update, [task_dropdown, criteria_check], [card1, card2, card3, chart1, chart2, result_md])
|
| 137 |
criteria_check.change(update, [task_dropdown, criteria_check], [card1, card2, card3, chart1, chart2, result_md])
|
| 138 |
|