Spaces:
Runtime error
Runtime error
Commit
·
4e6e631
1
Parent(s):
ea9debd
ty
Browse files- Readme.md +14 -0
- gui.py +66 -0
- requirements.txt +3 -0
Readme.md
ADDED
@@ -0,0 +1,14 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
---
|
2 |
+
title: Github-Tool
|
3 |
+
emoji: 🌍
|
4 |
+
colorFrom: red
|
5 |
+
colorTo: red
|
6 |
+
sdk: streamlet
|
7 |
+
sdk_version: 1.22.0
|
8 |
+
app_file: app.py
|
9 |
+
pinned: false
|
10 |
+
license: mit
|
11 |
+
|
12 |
+
---
|
13 |
+
|
14 |
+
Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
|
gui.py
ADDED
@@ -0,0 +1,66 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import streamlit as st
|
2 |
+
from github import Github
|
3 |
+
from github import UnknownObjectException
|
4 |
+
|
5 |
+
# Set up the Streamlit app
|
6 |
+
st.set_page_config(page_title="GitHub File Search", page_icon=":mag_right:")
|
7 |
+
|
8 |
+
# Replace YOUR_ACCESS_TOKEN with your GitHub personal access token
|
9 |
+
access_token = "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"
|
10 |
+
|
11 |
+
|
12 |
+
# Define a function to get all the repositories that contain a file with the given name
|
13 |
+
def get_repositories_with_file(filename):
|
14 |
+
# Search for the file on GitHub using the PyGitHub library
|
15 |
+
g = Github(access_token)
|
16 |
+
repositories = g.search_repositories(query=f"filename:{filename}", sort="stars", order="desc")
|
17 |
+
|
18 |
+
# Initialize a list to store the repository information
|
19 |
+
repo_info = []
|
20 |
+
|
21 |
+
# Loop through the repositories
|
22 |
+
for repo in repositories:
|
23 |
+
try:
|
24 |
+
# Get all the files in the repository
|
25 |
+
contents = repo.get_contents(path=filename)
|
26 |
+
|
27 |
+
# Check if the repository contains a file with the given name
|
28 |
+
for content in contents:
|
29 |
+
if content.name == filename:
|
30 |
+
repo_info.append({
|
31 |
+
"name": repo.name,
|
32 |
+
"description": repo.description,
|
33 |
+
"url": repo.html_url
|
34 |
+
})
|
35 |
+
break
|
36 |
+
|
37 |
+
except UnknownObjectException as e:
|
38 |
+
# Catch the exception if the file is not found in the repository
|
39 |
+
st.warning(f"File '{filename}' not found in repository '{repo.full_name}'.")
|
40 |
+
|
41 |
+
# Return the repository information
|
42 |
+
return repo_info
|
43 |
+
|
44 |
+
|
45 |
+
# Define the Streamlit app
|
46 |
+
def app():
|
47 |
+
# Set up the user interface
|
48 |
+
st.title("GitHub File Search")
|
49 |
+
st.write("Enter a file name to search for on GitHub:")
|
50 |
+
if filename := st.text_input("File name"):
|
51 |
+
# Get the repositories with the file
|
52 |
+
repo_info = get_repositories_with_file(filename)
|
53 |
+
|
54 |
+
# Display the repository information
|
55 |
+
if len(repo_info) > 0:
|
56 |
+
st.success(f"Found {len(repo_info)} repositories with the file '{filename}':")
|
57 |
+
for repo in repo_info:
|
58 |
+
st.write(f"- **{repo['name']}**: {repo['description']}")
|
59 |
+
st.write(f" URL: [{repo['url']}]({repo['url']})")
|
60 |
+
else:
|
61 |
+
st.warning(f"No repositories found with the file '{filename}'.")
|
62 |
+
|
63 |
+
|
64 |
+
# Run the Streamlit app
|
65 |
+
if __name__ == "__main__":
|
66 |
+
app()
|
requirements.txt
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
huggingface_hub
|
2 |
+
PyGithub
|
3 |
+
streamlit
|