Spaces:
Running
Running
| 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() | |