Gertie2013 commited on
Commit
21ce73a
·
verified ·
1 Parent(s): f89a870

Upload folder using huggingface_hub

Browse files
Files changed (2) hide show
  1. app.py +109 -0
  2. requirements.txt +1 -0
app.py ADDED
@@ -0,0 +1,109 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ import os
3
+ import subprocess
4
+ from pathlib import Path
5
+ import shutil
6
+
7
+ def clone_and_explore_repo(repo_url, selected_file=None):
8
+ # Clean up previous clone if exists
9
+ repo_name = repo_url.split("/")[-1].replace(".git", "")
10
+ clone_dir = Path(f"cloned_repos/{repo_name}")
11
+
12
+ if clone_dir.exists():
13
+ shutil.rmtree(clone_dir)
14
+
15
+ # Clone the repository
16
+ try:
17
+ subprocess.run(["git", "clone", repo_url, str(clone_dir)], check=True)
18
+ except subprocess.CalledProcessError as e:
19
+ return f"Error cloning repository: {str(e)}", None, None
20
+
21
+ # Get list of files
22
+ file_list = []
23
+ for root, _, files in os.walk(clone_dir):
24
+ for file in files:
25
+ file_path = os.path.relpath(os.path.join(root, file), clone_dir)
26
+ file_list.append(file_path)
27
+
28
+ # Read selected file if specified
29
+ file_content = ""
30
+ if selected_file and selected_file in file_list:
31
+ try:
32
+ with open(clone_dir / selected_file, "r", encoding="utf-8") as f:
33
+ file_content = f.read()
34
+ except Exception as e:
35
+ file_content = f"Error reading file: {str(e)}"
36
+
37
+ return "\n".join(file_list), file_content, gr.Dropdown(choices=file_list, value=selected_file)
38
+
39
+ # Custom theme for the app
40
+ custom_theme = gr.themes.Soft(
41
+ primary_hue="blue",
42
+ secondary_hue="indigo",
43
+ neutral_hue="slate",
44
+ font=gr.themes.GoogleFont("Inter"),
45
+ text_size="lg",
46
+ spacing_size="lg",
47
+ radius_size="md"
48
+ ).set(
49
+ button_primary_background_fill="*primary_600",
50
+ button_primary_background_fill_hover="*primary_700",
51
+ block_title_text_weight="600",
52
+ )
53
+
54
+ with gr.Blocks(theme=custom_theme) as demo:
55
+ gr.Markdown(
56
+ """
57
+ # GitHub Repository Explorer
58
+ ### Built with [anycoder](https://huggingface.co/spaces/akhaliq/anycoder)
59
+ Explore any GitHub repository by cloning it and browsing its contents.
60
+ """
61
+ )
62
+
63
+ with gr.Row():
64
+ repo_url = gr.Textbox(
65
+ label="GitHub Repository URL",
66
+ value="https://github.com/Gertie01/cuddly-palm-tree-boy.git",
67
+ placeholder="Enter GitHub repository URL ending with .git"
68
+ )
69
+ clone_btn = gr.Button("Clone Repository", variant="primary")
70
+
71
+ with gr.Row():
72
+ with gr.Column(scale=1):
73
+ file_list = gr.Textbox(label="Files in Repository", interactive=False, lines=10)
74
+ file_dropdown = gr.Dropdown(
75
+ label="Select File to View",
76
+ interactive=True,
77
+ allow_custom_value=False
78
+ )
79
+
80
+ with gr.Column(scale=2):
81
+ file_content = gr.Code(
82
+ label="File Content",
83
+ language="python",
84
+ interactive=False,
85
+ lines=20
86
+ )
87
+
88
+ # Event handlers
89
+ clone_btn.click(
90
+ fn=clone_and_explore_repo,
91
+ inputs=[repo_url, file_dropdown],
92
+ outputs=[file_list, file_content, file_dropdown]
93
+ )
94
+
95
+ file_dropdown.change(
96
+ fn=lambda repo_url, file: clone_and_explore_repo(repo_url, file)[1],
97
+ inputs=[repo_url, file_dropdown],
98
+ outputs=file_content
99
+ )
100
+
101
+ if __name__ == "__main__":
102
+ demo.launch(
103
+ title="GitHub Repository Explorer",
104
+ description="Clone and explore GitHub repositories",
105
+ footer_links=[
106
+ {"label": "GitHub", "url": "https://github.com"},
107
+ {"label": "Hugging Face", "url": "https://huggingface.co"}
108
+ ]
109
+ )
requirements.txt ADDED
@@ -0,0 +1 @@
 
 
1
+ gradio>=6.0.2