lvwerra HF staff commited on
Commit
6127ee8
β€’
1 Parent(s): 48dc2f2

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +41 -6
app.py CHANGED
@@ -2,10 +2,14 @@ import gradio as gr
2
  from huggingface_hub import hf_hub_download
3
  import json
4
  import gzip
5
-
6
 
7
  usernames = {}
8
 
 
 
 
 
9
  filepath = hf_hub_download(repo_id="bigcode/the-stack-username-to-repo", filename="username_to_repo.json.gz", repo_type="dataset", revision="v1.1")
10
  with gzip.open(filepath, 'r') as f:
11
  usernames["v1.1"] = json.loads(f.read().decode('utf-8'))
@@ -15,17 +19,44 @@ with gzip.open(filepath, 'r') as f:
15
  usernames["v1.0"] = json.loads(f.read().decode('utf-8'))
16
 
17
  text = """\
18
- ![](https://huggingface.co/spaces/bigcode/in-the-stack/resolve/main/banner.png)
19
  **_The Stack is an open governance interface between the AI community and the open source community._**
20
 
21
  # Am I in The Stack?
22
 
23
- As part of the BigCode project, we released and maintain [The Stack](https://huggingface.co/datasets/bigcode/the-stack), a 3.1 TB dataset of permissively licensed source code in 30 programming languages. One of our goals in this project is to give people agency over their source code by letting them decide whether or not it should be used to develop and evaluate machine learning models, as we acknowledge that not all developers may wish to have their data used for that purpose.
24
  """ + """\
25
 
26
  This tool lets you check if a repository under a given username is part of The Stack dataset. Would you like to have your data removed from future versions of The Stack? You can opt-out following the instructions [here](https://www.bigcode-project.org/docs/about/the-stack/#how-can-i-request-that-my-data-be-removed-from-the-stack).
27
  """
28
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
29
  def check_username(username, version):
30
  output_md = ""
31
  if username in usernames[version] and len(usernames[version][username])>0:
@@ -34,22 +65,26 @@ def check_username(username, version):
34
  output_md += f"**Yes**, there is code from **{len(repos)} {repo_word}** in The Stack:\n\n"
35
  for repo in repos:
36
  output_md += f"_{repo}_\n\n"
 
 
37
  else:
38
  output_md += "**No**, your code is not in The Stack."
39
- return output_md.strip()
40
 
41
  with gr.Blocks() as demo:
42
  with gr.Row():
43
  _, colum_2, _ = gr.Column(scale=1), gr.Column(scale=6), gr.Column(scale=1)
44
  with colum_2:
45
  gr.Markdown(text)
46
- version = gr.Dropdown(["v1.1", "v1.0"], label="The Stack version:", value="v1.1")
47
  username = gr.Text("", label="Your GitHub username:")
48
  check_button = gr.Button("Check!")
49
 
50
  repos = gr.Markdown()
 
 
51
 
52
- check_button.click(check_username, [username, version], repos)
53
 
54
 
55
  demo.launch()
 
2
  from huggingface_hub import hf_hub_download
3
  import json
4
  import gzip
5
+ import urllib
6
 
7
  usernames = {}
8
 
9
+ filepath = hf_hub_download(repo_id="bigcode/the-stack-username-to-repo", filename="username_to_repo.json.gz", repo_type="dataset", revision="v1.2")
10
+ with gzip.open(filepath, 'r') as f:
11
+ usernames["v1.2"] = json.loads(f.read().decode('utf-8'))
12
+
13
  filepath = hf_hub_download(repo_id="bigcode/the-stack-username-to-repo", filename="username_to_repo.json.gz", repo_type="dataset", revision="v1.1")
14
  with gzip.open(filepath, 'r') as f:
15
  usernames["v1.1"] = json.loads(f.read().decode('utf-8'))
 
19
  usernames["v1.0"] = json.loads(f.read().decode('utf-8'))
20
 
21
  text = """\
22
+ ![](https://huggingface.co/spaces/lvwerra/in-the-stack-gr/resolve/main/banner.png)
23
  **_The Stack is an open governance interface between the AI community and the open source community._**
24
 
25
  # Am I in The Stack?
26
 
27
+ As part of the BigCode project, we released and maintain [The Stack](https://huggingface.co/datasets/bigcode/the-stack), a 6 TB dataset of permissively licensed source code over 300 programming languages. One of our goals in this project is to give people agency over their source code by letting them decide whether or not it should be used to develop and evaluate machine learning models, as we acknowledge that not all developers may wish to have their data used for that purpose.
28
  """ + """\
29
 
30
  This tool lets you check if a repository under a given username is part of The Stack dataset. Would you like to have your data removed from future versions of The Stack? You can opt-out following the instructions [here](https://www.bigcode-project.org/docs/about/the-stack/#how-can-i-request-that-my-data-be-removed-from-the-stack).
31
  """
32
 
33
+ opt_out_text_template = """\
34
+ ### Opt-out
35
+
36
+ If you want your data to be removed from the stack and model training \
37
+ 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> \
38
+ (if the link doesn't work try right a right click and open 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) .\
39
+ """
40
+
41
+ opt_out_issue_title = """Opt-out request for {username}"""
42
+ opt_out_issue_body = """\
43
+ I request that the following data is removed from The Stack:
44
+
45
+ - Commits
46
+ - GitHub issue
47
+ {repo_list}
48
+
49
+ _Note_: If you don't want all resources to be included just remove the elements from the list above. If you would like to exclude all repositories and resources just add a single element "all" to the list.
50
+ """
51
+
52
+ def issue_url(username, repos):
53
+ title = urllib.parse.quote(opt_out_issue_title.format(username=username))
54
+ body = urllib.parse.quote(opt_out_issue_body.format(repo_list=" - "+ "\n - ".join(repos)))
55
+
56
+ opt_out_text = opt_out_text_template.format(title=title, body=body)
57
+
58
+ return opt_out_text
59
+
60
  def check_username(username, version):
61
  output_md = ""
62
  if username in usernames[version] and len(usernames[version][username])>0:
 
65
  output_md += f"**Yes**, there is code from **{len(repos)} {repo_word}** in The Stack:\n\n"
66
  for repo in repos:
67
  output_md += f"_{repo}_\n\n"
68
+
69
+ return output_md.strip(), issue_url(username, repos)
70
  else:
71
  output_md += "**No**, your code is not in The Stack."
72
+ return output_md.strip(), ""
73
 
74
  with gr.Blocks() as demo:
75
  with gr.Row():
76
  _, colum_2, _ = gr.Column(scale=1), gr.Column(scale=6), gr.Column(scale=1)
77
  with colum_2:
78
  gr.Markdown(text)
79
+ version = gr.Dropdown(["v1.2", "v1.1", "v1.0"], label="The Stack version:", value="v1.2")
80
  username = gr.Text("", label="Your GitHub username:")
81
  check_button = gr.Button("Check!")
82
 
83
  repos = gr.Markdown()
84
+ opt_out = gr.Markdown()
85
+
86
 
87
+ check_button.click(check_username, [username, version], [repos, opt_out])
88
 
89
 
90
  demo.launch()