File size: 1,741 Bytes
9ec8a57
 
 
 
b943e82
 
9ec8a57
 
 
 
 
 
 
 
 
 
 
 
 
22ef21f
9ec8a57
 
 
 
 
 
 
 
 
 
 
d6da45f
9ec8a57
 
d6da45f
9ec8a57
 
 
 
 
 
 
d6da45f
 
 
9ec8a57
 
d6da45f
9ec8a57
 
d6da45f
9ec8a57
 
 
b943e82
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
import json
import os
import tempfile

import gradio as gr

from utils import evaluate, report


def scoring(tasks: list[dict]):
    return tasks


def process_jsonl_file(jsonl_file_path: str, api_key: str):
    try:
        content = open(jsonl_file_path, "r", encoding="utf-8").readlines()
        json_data = [json.loads(line) for line in content]

        if api_key is not None and api_key != "":
            json_data = evaluate(json_data, api_key)

        html_content = report(tasks=json_data)

        file_name_with_ext = os.path.basename(jsonl_file_path)
        file_name, _ = os.path.splitext(file_name_with_ext)

        with tempfile.NamedTemporaryFile(
            delete=False, prefix=f"{file_name}-report-", suffix=".html", mode="w", encoding="utf-8"
        ) as temp_file:
            temp_file.write(html_content)
            output_file = temp_file.name
        return output_file, ""

    except Exception as e:
        return None, e


# Gradioデモ
with gr.Blocks() as demo:
    gr.Markdown("## ELYZA-tasks-100(-TV) セルフ評価ページ")

    jsonl_input = gr.File(label="JSONLファイルをアップロード")
    api_key_input = gr.Textbox(label="GeminiのAPIキー(スコアのセルフ評価を行う場合)", type="password")
    gr.Markdown("APIキーの発行は[こちら](https://aistudio.google.com/app/apikey)")
    process_button = gr.Button("レポートを作成")

    output_file = gr.File(label="セルフ評価レポート")
    output_text = gr.Textbox(label="システムメッセージ")

    process_button.click(
        process_jsonl_file, inputs=[jsonl_input, api_key_input], outputs=[output_file, output_text]
    )

demo.launch()

if __name__ == "__main__":
    demo.launch()