anton-l HF staff commited on
Commit
e7e3479
β€’
1 Parent(s): 70bb04d

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +5 -27
app.py CHANGED
@@ -1,31 +1,10 @@
1
  import gradio as gr
2
  from huggingface_hub import hf_hub_download
3
- import json_stream as json
4
  import gzip
5
  import urllib
6
- from collections import defaultdict
7
- import gc
8
- import sys
9
-
10
- usernames = defaultdict(dict)
11
-
12
- versions = ["v1.0", "v1.1", "v1.2", "v2.0", "v2.0.1", "v2.1.0"]
13
- versions = [sys.intern(version) for version in versions]
14
-
15
- for version in versions:
16
- print(f"Loading {version}")
17
- branch = version if version != "v1.0" else "main"
18
- filepath = hf_hub_download(repo_id="bigcode/the-stack-username-to-repo", filename="username_to_repo.json.gz", repo_type="dataset", revision=branch)
19
- with gzip.open(filepath, 'r') as f:
20
- data = json.load(f)
21
- for username, repos in data.items():
22
- username = username.lower()
23
- for repo in repos:
24
- if repo not in usernames[username]:
25
- usernames[username][repo] = []
26
- usernames[username][repo].append(version)
27
- del data
28
- gc.collect()
29
 
30
  text = """\
31
  ![](https://huggingface.co/spaces/lvwerra/in-the-stack-gr/resolve/main/banner.png)
@@ -80,9 +59,8 @@ def issue_url(username, repos):
80
  def check_username(username, version):
81
  username = username.lower()
82
  output_md = ""
83
- repos = []
84
- if username in usernames:
85
- repos = [repo for repo, versions in usernames[username].items() if version in versions]
86
 
87
  if repos:
88
  repo_word = "repository" if len(repos)==1 else "repositories"
 
1
  import gradio as gr
2
  from huggingface_hub import hf_hub_download
 
3
  import gzip
4
  import urllib
5
+ import duckdb
6
+
7
+ db = duckdb.connect("repos.duckdb")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
8
 
9
  text = """\
10
  ![](https://huggingface.co/spaces/lvwerra/in-the-stack-gr/resolve/main/banner.png)
 
59
  def check_username(username, version):
60
  username = username.lower()
61
  output_md = ""
62
+ repos = db.sql(f"SELECT repo FROM repos WHERE user='{username}' AND version='{version}' ORDER BY repo").collectall()
63
+ repos = [repo[0] for repo in repos]
 
64
 
65
  if repos:
66
  repo_word = "repository" if len(repos)==1 else "repositories"