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()