Not-Grim-Refer commited on
Commit
2e43cec
1 Parent(s): 24efef8

Upload 6 files

Browse files
Files changed (5) hide show
  1. .gitignore +26 -0
  2. .gptignore +30 -0
  3. README.md +1 -1
  4. app.py +105 -0
  5. requirements.txt +1 -0
.gitignore ADDED
@@ -0,0 +1,26 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Python artifacts
2
+ __pycache__/
3
+ *.pyc
4
+ *.pyo
5
+ *.pyd
6
+
7
+ # Output file
8
+ output.txt
9
+
10
+ # Unit test artifacts
11
+ .coverage
12
+ .coverage.
13
+ htmlcov/
14
+
15
+ # Virtual environment
16
+ venv/
17
+ *.egg-info/
18
+
19
+ # Jupyter Notebook
20
+ .ipynb_checkpoints/
21
+
22
+ # Miscellaneous
23
+ *.swp
24
+ *.swo
25
+ *.swn
26
+ *~
.gptignore ADDED
@@ -0,0 +1,30 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ __pycache__/
2
+ *.pyc
3
+ *.log
4
+ .git/*
5
+ .gptignore
6
+ .gitattributes
7
+ LICENSE
8
+ .github/*
9
+ .tox/*
10
+ .mypy_cache/*
11
+ *.whl
12
+ *.tar
13
+ *.tar.gz
14
+ .gitignore
15
+ *.env*
16
+ *.png
17
+ *.jpeg
18
+ *.jpg
19
+ *bin/*
20
+ /.git/
21
+ /.idea
22
+ /.gradle
23
+ /build
24
+ /target
25
+ /test_data
26
+ test_gpt_repository_loader.py
27
+ output.txt
28
+ /data
29
+ *.jar
30
+ *.class
README.md CHANGED
@@ -6,7 +6,7 @@ colorTo: indigo
6
  sdk: streamlit
7
  sdk_version: 1.32.2
8
  app_file: app.py
9
- pinned: false
10
  license: apache-2.0
11
  ---
12
 
 
6
  sdk: streamlit
7
  sdk_version: 1.32.2
8
  app_file: app.py
9
+ pinned: true
10
  license: apache-2.0
11
  ---
12
 
app.py ADDED
@@ -0,0 +1,105 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import os
2
+ import fnmatch
3
+ import streamlit as st
4
+ import sys
5
+ import base64
6
+
7
+ # Function definitions remain the same
8
+ def get_ignore_list(ignore_file_path):
9
+ ignore_list = []
10
+ with open(ignore_file_path, 'r') as ignore_file:
11
+ for line in ignore_file:
12
+ if sys.platform == "win32":
13
+ line = line.replace("/", "\\")
14
+ ignore_list.append(line.strip())
15
+ return ignore_list
16
+
17
+ def should_ignore(file_path, ignore_list):
18
+ for pattern in ignore_list:
19
+ if fnmatch.fnmatch(file_path, pattern):
20
+ return True
21
+ return False
22
+
23
+ def process_repository(repo_path, ignore_list):
24
+ structure = "Project Directory Structure:\n"
25
+ contents = ""
26
+ for root, dirs, files in os.walk(repo_path):
27
+ level = root.replace(repo_path, '').count(os.sep)
28
+ indent = ' ' * level
29
+ subindent = ' ' * (level + 1)
30
+ relative_root = os.path.relpath(root, repo_path)
31
+ if not should_ignore(relative_root, ignore_list):
32
+ structure += '{}- {}\n'.format(indent, os.path.basename(root))
33
+ for file in files:
34
+ relative_file_path = os.path.relpath(os.path.join(root, file), repo_path)
35
+ if not should_ignore(relative_file_path, ignore_list):
36
+ structure += '{}- {}\n'.format(subindent, file)
37
+ file_path = os.path.join(root, file)
38
+ with open(file_path, 'r', errors='ignore') as file:
39
+ file_contents = file.read()
40
+ contents += "-" * 4 + "\n"
41
+ contents += f"{relative_file_path}\n"
42
+ contents += f"{file_contents}\n"
43
+ structure += "End Project Directory Structure Visual\n\n"
44
+ return structure, contents
45
+
46
+ def download_button(object_to_download, download_filename, button_text):
47
+ if isinstance(object_to_download, bytes):
48
+ pass
49
+ elif isinstance(object_to_download, str):
50
+ object_to_download = object_to_download.encode('utf-8')
51
+ else:
52
+ raise ValueError(f"object_to_download must be a str or bytes, got {type(object_to_download)}")
53
+
54
+ try:
55
+ b64 = base64.b64encode(object_to_download).decode()
56
+ href = f'<a href="data:file/txt;base64,{b64}" download="{download_filename}" class="btn btn-primary" role="button">{button_text}</a>'
57
+ st.markdown(href, unsafe_allow_html=True)
58
+ except Exception as e:
59
+ st.error(f"An error occurred while creating the download link: {e}")
60
+
61
+ # Updated Streamlit UI to include new features
62
+ st.title("Git Repository Loader with Web UI")
63
+
64
+ # Organizing input and buttons using columns
65
+ col1, col2, col3 = st.columns([3, 2, 2])
66
+ with col1:
67
+ repo_path = st.text_input("Enter the path to your Git repository:", "")
68
+ with col2:
69
+ process_button = st.button("Process Repository")
70
+ with col3:
71
+ copy_button = st.button("Copy to Clipboard")
72
+
73
+ if process_button:
74
+ with st.spinner('Processing the repository...'):
75
+ ignore_file_path = os.path.join(repo_path, ".gptignore")
76
+ if sys.platform == "win32":
77
+ ignore_file_path = ignore_file_path.replace("/", "\\")
78
+
79
+ if not os.path.exists(ignore_file_path):
80
+ HERE = os.path.dirname(os.path.abspath(__file__))
81
+ ignore_file_path = os.path.join(HERE, ".gptignore")
82
+
83
+ if os.path.exists(ignore_file_path):
84
+ ignore_list = get_ignore_list(ignore_file_path)
85
+ else:
86
+ ignore_list = []
87
+
88
+ structure, contents = process_repository(repo_path, ignore_list)
89
+ full_output = f"### Project Directory Structure\n{structure}\n### Files Content\n{contents}"
90
+
91
+ st.markdown("### Output")
92
+ download_button(full_output, "repository_output.md", "Download Output as Markdown")
93
+
94
+ with st.expander("View Project Directory Structure"):
95
+ st.text(structure)
96
+ with st.expander("View Files Content"):
97
+ st.text(contents)
98
+
99
+ if copy_button:
100
+ st.experimental_set_query_params(full_output=full_output)
101
+ js = f"navigator.clipboard.writeText(`{full_output}`)"
102
+ st.components.v1.html(f"<script>{js}</script>", height=0, width=0)
103
+ st.sidebar.success("Copied to clipboard!")
104
+
105
+ st.success("Process completed. Review the results above.")
requirements.txt ADDED
@@ -0,0 +1 @@
 
 
1
+ streamlit