CoolFace
Apppublic

Robo2000/06-Big-Code-Search

sourceHugging Faceupdated 4y agoView on Hugging Face
0likes
app.py79 linesDownload Raw Back to root
1import gradio as gr2from huggingface_hub import hf_hub_download3import json4import gzip5 6 7usernames = {}8 9 10filepath = hf_hub_download(repo_id="bigcode/the-stack-username-to-repo", filename="username_to_repo.json.gz", repo_type="dataset", revision="v1.1")11with gzip.open(filepath, 'r') as f:12    usernames["v1.1"] = json.loads(f.read().decode('utf-8'))13 14filepath = hf_hub_download(repo_id="bigcode/the-stack-username-to-repo", filename="username_to_repo.json.gz", repo_type="dataset")15with gzip.open(filepath, 'r') as f:16    usernames["v1.0"] = json.loads(f.read().decode('utf-8'))17 18text = """\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 Keyword22URL: [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 26def 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 38def check_keyword(username, version):39    output_md = ""40    maxhitcount = 10041    maxrepos = 70000000  #6M user entries * up to 18 per user42    currenthitcount=043    currentrepos=044    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 += 151            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 += 156                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 64with 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 79demo.launch()