Robo2000 commited on
Commit
f1aa5f6
1 Parent(s): f5f69d1

Upload app.py

Browse files
Files changed (1) hide show
  1. app.py +79 -0
app.py ADDED
@@ -0,0 +1,79 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ from huggingface_hub import hf_hub_download
3
+ import json
4
+ import gzip
5
+
6
+
7
+ usernames = {}
8
+
9
+
10
+ filepath = hf_hub_download(repo_id="bigcode/the-stack-username-to-repo", filename="username_to_repo.json.gz", repo_type="dataset", revision="v1.1")
11
+ with gzip.open(filepath, 'r') as f:
12
+ usernames["v1.1"] = json.loads(f.read().decode('utf-8'))
13
+
14
+ filepath = hf_hub_download(repo_id="bigcode/the-stack-username-to-repo", filename="username_to_repo.json.gz", repo_type="dataset")
15
+ with gzip.open(filepath, 'r') as f:
16
+ usernames["v1.0"] = json.loads(f.read().decode('utf-8'))
17
+
18
+ text = """\
19
+ ![](https://huggingface.co/spaces/bigcode/in-the-stack/resolve/main/banner.png)
20
+ **_The Stack is an open governance interface between the AI community and the open source community._**
21
+ # Stack Search By Keyword
22
+ URL: [The Stack](https://huggingface.co/datasets/bigcode/the-stack), This search engine will match your search term and find up to 100 matches by keyword for example BeatSaber.
23
+ """ + """\
24
+ """
25
+
26
+ def check_username(username, version):
27
+ output_md = ""
28
+ if username in usernames[version] and len(usernames[version][username])>0:
29
+ repos = usernames[version][username]
30
+ repo_word = "repository" if len(repos)==1 else "repositories"
31
+ output_md += f"**Yes**, there is code from **{len(repos)} {repo_word}** in The Stack:\n\n"
32
+ for repo in repos:
33
+ output_md += f"_{repo}_\n\n"
34
+ else:
35
+ output_md += "**No**, your code is not in The Stack."
36
+ return output_md.strip()
37
+
38
+ def check_keyword(username, version):
39
+ output_md = ""
40
+ maxhitcount = 100
41
+ maxrepos = 70000000 #6M user entries * up to 18 per user
42
+ currenthitcount=0
43
+ currentrepos=0
44
+ for repolist in usernames[version]:
45
+ #print(repolist)
46
+ repos = usernames[version][repolist]
47
+ repo_word = "repository" if len(repos)==1 else "repositories"
48
+ #output_md += f"**Yes**, there is code from **{len(repos)} {repo_word}** in The Stack:\n\n"
49
+ for repo in repos:
50
+ currentrepos += 1
51
+ if currentrepos > maxrepos:
52
+ output_md += f"**Found maximum repos**, Count: **{currentrepos}** in The Stack:\n\n"
53
+ return output_md.strip()
54
+ if username in repo:
55
+ currenthitcount += 1
56
+ output_md += f"_<a href=https://github.com/{repo} target=_blank>{repo}</a>_\n\n"
57
+ if currenthitcount > maxhitcount:
58
+ output_md += f"**Found maximum hits**, Count: **{currenthitcount}** in The Stack:\n\n"
59
+ return output_md.strip()
60
+ else:
61
+ output_md += "**Searched All Repos**, Above found in The Stack."
62
+ return output_md.strip()
63
+
64
+ with gr.Blocks() as demo:
65
+ with gr.Row():
66
+ _, colum_2, _ = gr.Column(scale=1), gr.Column(scale=6), gr.Column(scale=1)
67
+ with colum_2:
68
+ gr.Markdown(text)
69
+ version = gr.Dropdown(["v1.1", "v1.0"], label="The Stack version:", value="v1.1")
70
+ username = gr.Text("", label="Keyword to match against repos e.g. BeatSaber")
71
+ check_button = gr.Button("Check!")
72
+
73
+ repos = gr.Markdown()
74
+
75
+ #check_button.click(check_username, [username, version], repos)
76
+ check_button.click(check_keyword, [username, version], repos)
77
+
78
+
79
+ demo.launch()