Skip to content

Commit

Permalink
Download Model Labels
Browse files Browse the repository at this point in the history
  • Loading branch information
bbengfort committed Oct 9, 2024
1 parent 64032f4 commit 459081b
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 1 deletion.
4 changes: 3 additions & 1 deletion parlance/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,10 @@

from parley.views import ReviewTaskDetail
from parley.views import LLMList, LLMDetail
from parley.views import EvaluationList, EvaluationDetail
from parley.views import DownloadPrompts, DownloadAnalytics
from parlance.views import Dashboard, AccountSettings, AccountProfile
from parley.views import UploaderFormView, CreateReviewTask, ResponseDetail
from parley.views import EvaluationList, EvaluationDetail, DownloadPrompts


##########################################################################
Expand All @@ -55,6 +56,7 @@
path("evaluations/", EvaluationList.as_view(), name="evaluations-list"),
path("evaluations/<uuid:pk>", EvaluationDetail.as_view(), name="evaluation-detail"),
path("evaluations/<uuid:pk>/download", DownloadPrompts.as_view(), name="evaluation-download"),
path("evaluations/<uuid:pk>/analytics", DownloadAnalytics.as_view(), name="evaluation-analytics"),
path("evaluations/create-review-task", CreateReviewTask.as_view(), name="create-review-task"),

path("reviews/<int:pk>", ReviewTaskDetail.as_view(), name="review-task"),
Expand Down
3 changes: 3 additions & 0 deletions parley/templates/evaluation/detail.html
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@
<span class="fe fe-edit"></span>
</a>
{% endif %}
<a href="{% url 'evaluation-analytics' evaluation.pk %}" class="btn btn-info" title="Download CSV for Analytics">
<span class="fe fe-download-cloud"></span>
</a>
<a href="{% url 'evaluation-download' evaluation.pk %}" class="btn btn-secondary" title="Download Prompts">
<span class="fe fe-download"></span>
</a>
Expand Down
40 changes: 40 additions & 0 deletions parley/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
## Imports
##########################################################################

import csv
import json

from collections import defaultdict
Expand All @@ -25,6 +26,7 @@
from django.db import transaction
from django.contrib import messages
from django.urls import reverse_lazy
from django.utils.text import slugify
from django.utils.safestring import mark_safe
from django.views.generic.edit import FormView
from django.views.generic import DetailView, ListView
Expand Down Expand Up @@ -180,6 +182,44 @@ def get(self, request, pk=None):
}

reply.write(json.dumps(data) + "\n")

return reply


class DownloadAnalytics(View):

def get(self, request, pk=None):
if pk is None or not Evaluation.objects.filter(pk=pk).exists():
raise Http404("evaluation not found")

evaluation = Evaluation.objects.get(pk=pk)
filename = slugify(f"{evaluation.name}") + ".csv"

reply = HttpResponse(
content_type="text/csv",
headers={"Content-Disposition": f'attachment; filename="{filename}"'},
)

fieldnames = ["id", "prompt", "expected"]
models = [(llm.id, llm.name, llm.version) for llm in evaluation.llms.all()]
for _, name, version in models:
fieldnames.append(name + "-" + version)

prompts = Prompt.objects.filter(evaluation__id=pk, exclude=False)
writer = csv.DictWriter(reply, fieldnames=fieldnames)
writer.writeheader()

for prompt in prompts:
values = [prompt.id, str(prompt), prompt.expected_label]
for id, _, _ in models:
response = Response.objects.filter(model__id=id, prompt=prompt).first()
if response:
values.append(response.label)
else:
values.append(None)

writer.writerow(dict(zip(fieldnames, values)))

return reply


Expand Down

0 comments on commit 459081b

Please sign in to comment.