File size: 1,488 Bytes
65581f0
308d831
65581f0
 
308d831
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
60d7e20
 
 
 
65581f0
60d7e20
65581f0
60d7e20
 
 
 
 
308d831
 
 
 
 
 
 
 
60d7e20
 
 
 
 
 
 
 
 
 
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
59
import gradio as gr
from datasets import load_dataset
from chatgpt_conversation_parser.main import fetch_and_parse_conversation


def add_to_dataset(title, data):
    dataset = load_dataset("beratcmn/parse-gpt-tr", cache_dir="./datasets")
    model = data[0]["model"]["slug"]
    id = data[0]["id"]

    for message in data:
        del message["model"]
        del message["id"]

    data_dict = {"id": id, "model": model, "messages": data}

    dataset = dataset["train"].add_item(data_dict)
    dataset.push_to_hub("beratcmn/parse-gpt-tr")


def action(url, cb):
    result = fetch_and_parse_conversation(url)
    title, data = result
    yield result
    if cb:
        add_to_dataset(title, data)


with gr.Blocks() as demo:
    gr.Markdown(
        """
        # ChatGPT Conversation Parser

        This is a simple tool to fetch and parse a conversation from ChatGPT's web interface.

        Enter the URL of the conversation to fetch and parse. The tool will return a JSONL file and the parsed conversation.
        """.strip()
    )

    gr.Interface(
        fn=action,
        inputs=[
            "text",
            gr.Checkbox(
                True,
                label="Add this conversation to the public dataset?",
            ),
        ],
        outputs=[gr.DownloadButton(label="Download JSONL"), gr.JSON()],
    )

    gr.Markdown(
        """
        Made with ❤️ by [Berat Çimen](https://www.beratcimen.com/).
        """.strip()
    )

    demo.launch()