File size: 2,022 Bytes
c802e8d
a6b9e44
 
168366e
a6b9e44
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
c802e8d
 
 
 
 
 
 
 
 
 
 
 
a6b9e44
c802e8d
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
import gradio as gr
from huggingface_hub import Repository
from github import Github

# Define a function to get the 10 repositories with the largest file of the given name
def get_repositories_with_largest_file(filename):
    # Search for the file on GitHub using the Hugging Face API
    repositories = Repository.search(query=filename, provider="github")
    # Initialize a list to store the repository information
    repo_info = []
    # Loop through the repositories and get the largest file size
    for repo in repositories[:10]:
        # Get the repository information using the PyGitHub library
        g = Github()
        repository = g.get_repo(repo.full_name)
        # Get the largest file in the repository
        largest_file = None
        largest_file_size = 0
        for file in repository.get_files():
            if file.name == filename and file.size > largest_file_size:
                largest_file = file
                largest_file_size = file.size
        # Add the repository information to the list
        if largest_file:
            repo_info.append({
                "name": repo.name,
                "description": repo.description,
                "size": largest_file_size,
                "url": repo.html_url
            })
    # Return the repository information
    return repo_info

# Define the Gradio app
def app(filename):
    # Get the repositories with the largest file of the given name
    repo_info = get_repositories_with_largest_file(filename)
    # Display the repository information
    if repo_info:
        output = f"Top 10 repositories with the largest {filename}:\n"
        for index, repo in enumerate(repo_info):
            output += f"{index+1}. [{repo['name']}]({repo['url']}) - {repo['size']} bytes\n {repo['description']}\n"
    else:
        output = f"No repositories found with the file name {filename}."
    return output

# Run the Gradio app
iface = gr.Interface(fn=app, inputs="text", outputs="text", title="GitHub File Search")
iface.launch()