|
import gradio as gr |
|
from repo2txt.decoder import ( |
|
clone_repo, |
|
get_directory_structure, |
|
extract_all_files_contents, |
|
write_output_file, |
|
cleanup, |
|
) |
|
|
|
|
|
def process_repository(repo_url_or_shorthand): |
|
"""Process the GitHub repository and return the content of the output file.""" |
|
|
|
clone_dir = "temp_repo" |
|
output_file = "output.txt" |
|
|
|
try: |
|
|
|
clone_repo(repo_url_or_shorthand, clone_dir) |
|
|
|
|
|
directory_structure = get_directory_structure(clone_dir) |
|
file_contents = extract_all_files_contents(clone_dir) |
|
|
|
|
|
write_output_file(output_file, directory_structure, file_contents) |
|
|
|
|
|
with open(output_file, "r", encoding="utf-8") as file: |
|
output_content = file.read() |
|
|
|
|
|
cleanup(clone_dir) |
|
|
|
return output_content, output_file |
|
|
|
except Exception as e: |
|
return f"An error occurred: {e}", None |
|
|
|
|
|
|
|
with gr.Blocks(theme="gradio/soft", title="repo2txt") as demo: |
|
gr.Markdown("# repo2txt") |
|
|
|
with gr.Row(): |
|
repo_url_input = gr.Textbox( |
|
label="GitHub Repository URL or Shorthand",placeholder="e.g., user/repo or https://github.com/user/repo") |
|
|
|
process_button = gr.Button("Process Repository") |
|
|
|
with gr.Row(): |
|
txt_output = gr.File(label="Download txt file") |
|
with gr.Row(): |
|
result_output = gr.Textbox(label="Result",lines=1,placeholder="Processing result will be shown here") |
|
|
|
process_button.click(process_repository, inputs=repo_url_input, outputs=[result_output, txt_output]) |
|
|
|
|
|
if __name__ == "__main__": |
|
demo.launch() |
|
|