File size: 3,511 Bytes
b04da32
 
 
 
1168a3b
b04da32
 
 
4c11c36
342ec66
4c11c36
b04da32
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
4c11c36
b04da32
 
 
 
 
 
 
 
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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
import gradio as gr
import duckdb
import urllib.parse

PARQUET_PATH = "/data/v3_repos.parquet"

con = duckdb.connect()

huggy_html = '<img src="https://huggingface.co/spaces/HuggingFaceCode/in-the-stack/resolve/main/huggy.png" style="width: 20%;">'

text = """\
# Am I in The Stack?

[The Stack v3](https://huggingface.co/datasets/HuggingFaceCode/stack-v3-train) is \
a 15.9 TB dataset of source code across 713 programming languages from 173M repositories, \
crawled from GitHub in 2025.

We want to give developers agency over their source code \
by letting them decide whether or not it should be used to develop and evaluate \
machine learning models.

Enter your GitHub username below to check if any of your repositories are in The Stack v3. \
If your code is found, you will get a pre-filled opt-out link \
that submits a properly formatted removal request on your behalf. \
**Please use this tool to submit opt-out requests** rather than opening issues manually β€” \
it ensures your request can be processed quickly and correctly.
"""

opt_out_text_template = """\
### Opt-out

If you want your data to be removed from The Stack and model training, \
open an issue with <a href="https://github.com/bigcode-project/opt-out-v2/issues/new?title={title}&body={body}" target="_blank">this link</a> \
(if the link doesn't work, try right-clicking and opening it in a new tab) \
or visit [https://github.com/bigcode-project/opt-out-v2/issues/new?&template=opt-out-request.md](https://github.com/bigcode-project/opt-out-v2/issues/new?&template=opt-out-request.md).\
"""

opt_out_issue_title = "Opt-out request for {username}"
opt_out_issue_body = """\
I request that the following data is removed from The Stack:

{repo_list}

_Note_: If you don't want all repositories removed, edit the list above. \
To exclude everything under your username, replace the list with a single "all" entry.
"""


def issue_url(username, repos):
    title = urllib.parse.quote(opt_out_issue_title.format(username=username))
    body = urllib.parse.quote(
        opt_out_issue_body.format(repo_list=" - " + "\n - ".join(repos))
    )
    return opt_out_text_template.format(title=title, body=body)


def check_username(username):
    username = username.strip()
    if not username:
        return "", ""

    repos = con.execute(
        f"""SELECT repo FROM read_parquet('{PARQUET_PATH}')
            WHERE "user" = $1 ORDER BY repo""",
        [username.lower()],
    ).fetchall()
    repos = [row[0] for row in repos]

    if not repos:
        return "**No**, your code is not in The Stack v3.", ""

    repo_word = "repository" if len(repos) == 1 else "repositories"
    lines = [f"**Yes**, there is code from **{len(repos)} {repo_word}** in The Stack v3:\n"]
    for repo in repos:
        full = f"{username}/{repo}"
        lines.append(f"[{full}](https://github.com/{full})\n")
    output_md = "\n".join(lines).strip()

    full_names = [f"{username}/{r}" for r in repos]
    return output_md, issue_url(username, full_names)


with gr.Blocks() as demo:
    with gr.Row():
        _, col, _ = gr.Column(scale=1), gr.Column(scale=6), gr.Column(scale=1)
        with col:
            gr.HTML(huggy_html)
            gr.Markdown(text)
            username = gr.Text("", label="Your GitHub username:")
            check_button = gr.Button("Check!")
            repos_md = gr.Markdown()
            opt_out_md = gr.Markdown()
            check_button.click(check_username, [username], [repos_md, opt_out_md])

demo.launch()