Not-Grim-Refer commited on
Commit
c802e8d
·
1 Parent(s): 86c4ec4

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +16 -34
app.py CHANGED
@@ -1,10 +1,7 @@
1
- import streamlit as st
2
  from huggingface_hub import Repository
3
  from github import Github
4
 
5
- # Set up the Streamlit app
6
- st.set_page_config(page_title="GitHub File Search", page_icon=":mag_right:")
7
-
8
  # Define a function to get the 10 repositories with the largest file of the given name
9
  def get_repositories_with_largest_file(filename):
10
  # Search for the file on GitHub using the Hugging Face API
@@ -34,34 +31,19 @@ def get_repositories_with_largest_file(filename):
34
  # Return the repository information
35
  return repo_info
36
 
37
- # Define the Streamlit app
38
- def app():
39
- # Set up the user interface
40
- st.title("GitHub File Search")
41
- st.write("Enter a file name to search for on GitHub:")
42
- filename = st.text_input("File name")
43
- if filename:
44
- if "." not in filename:
45
- st.error(f"{filename} is not a valid file name. Please enter a valid file name with the file extension.")
46
- else:
47
- # Get the repositories with the largest file of the given name
48
- repo_info = get_repositories_with_largest_file(filename)
49
- # Display the repository information
50
- if repo_info:
51
- st.write(f"Top 10 repositories with the largest {filename}:")
52
- for index, repo in enumerate(repo_info):
53
- st.write(f"{index+1}. [{repo['name']}]({repo['url']}) - {repo['size']} bytes")
54
- st.write(f" {repo['description']}")
55
- else:
56
- st.warning(f"No repositories found with the file name {filename}.")
57
- # Add a button to download the results as a text file
58
- st.download_button(
59
- label="Download results as text file",
60
- data='\n\n'.join([f"{index+1}. {repo['name']} - {repo['size']} bytes\n{repo['url']}\n{repo['description']}" for index, repo in enumerate(repo_info)]),
61
- file_name=f"GitHub File Search Results - {filename}.txt",
62
- mime="text/plain"
63
- )
64
 
65
- # Run the Streamlit app
66
- if __name__ == "__main__":
67
- app()
 
1
+ import gradio as gr
2
  from huggingface_hub import Repository
3
  from github import Github
4
 
 
 
 
5
  # Define a function to get the 10 repositories with the largest file of the given name
6
  def get_repositories_with_largest_file(filename):
7
  # Search for the file on GitHub using the Hugging Face API
 
31
  # Return the repository information
32
  return repo_info
33
 
34
+ # Define the Gradio app
35
+ def app(filename):
36
+ # Get the repositories with the largest file of the given name
37
+ repo_info = get_repositories_with_largest_file(filename)
38
+ # Display the repository information
39
+ if repo_info:
40
+ output = f"Top 10 repositories with the largest {filename}:\n"
41
+ for index, repo in enumerate(repo_info):
42
+ output += f"{index+1}. [{repo['name']}]({repo['url']}) - {repo['size']} bytes\n {repo['description']}\n"
43
+ else:
44
+ output = f"No repositories found with the file name {filename}."
45
+ return output
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
46
 
47
+ # Run the Gradio app
48
+ iface = gr.Interface(fn=app, inputs="text", outputs="text", title="GitHub File Search")
49
+ iface.launch()