naman1102 commited on
Commit
791be58
·
1 Parent(s): 5b7f342

one_button

Browse files
Files changed (2) hide show
  1. analyzer.py +12 -1
  2. app.py +11 -8
analyzer.py CHANGED
@@ -30,10 +30,21 @@ def combine_repo_files_for_llm(repo_dir="repo_files", output_file="combined_repo
30
  file_path = os.path.join(root, file)
31
  try:
32
  with open(file_path, "r", encoding="utf-8") as f:
33
- combined_content.append(f"\n# File: {file_path}\n")
34
  combined_content.append(f.read())
35
  except Exception as e:
36
  combined_content.append(f"\n# Could not read {file_path}: {e}\n")
37
  with open(output_file, "w", encoding="utf-8") as out_f:
38
  out_f.write("\n".join(combined_content))
39
  return output_file
 
 
 
 
 
 
 
 
 
 
 
 
30
  file_path = os.path.join(root, file)
31
  try:
32
  with open(file_path, "r", encoding="utf-8") as f:
33
+ combined_content.append(f"\n# ===== File: {file} =====\n")
34
  combined_content.append(f.read())
35
  except Exception as e:
36
  combined_content.append(f"\n# Could not read {file_path}: {e}\n")
37
  with open(output_file, "w", encoding="utf-8") as out_f:
38
  out_f.write("\n".join(combined_content))
39
  return output_file
40
+
41
+ def analyze_combined_file(output_file="combined_repo.txt"):
42
+ """
43
+ Reads the combined file and passes its contents to analyze_code, returning the LLM's output.
44
+ """
45
+ try:
46
+ with open(output_file, "r", encoding="utf-8") as f:
47
+ code = f.read()
48
+ return analyze_code(code)
49
+ except Exception as e:
50
+ return f"Error analyzing combined file: {e}"
app.py CHANGED
@@ -2,7 +2,7 @@ import gradio as gr
2
  import regex as re
3
  import csv
4
  import pandas as pd
5
- from analyzer import combine_repo_files_for_llm
6
  from hf_utils import download_space_repo
7
 
8
  # from hf_utils import download_space_repo
@@ -42,20 +42,22 @@ def process_repo_input_and_store(text):
42
  df = pd.read_csv(csv_filename)
43
  return df
44
 
45
- def show_combined_repo():
46
  if not last_repo_ids:
47
- return "No repo ID available. Please submit repo IDs first."
48
  first_repo_id = last_repo_ids[0]
49
  try:
50
  download_space_repo(first_repo_id, local_dir="repo_files")
51
  except Exception as e:
52
- return f"Error downloading repo: {e}"
53
  txt_path = combine_repo_files_for_llm()
54
  try:
55
  with open(txt_path, "r", encoding="utf-8") as f:
56
- return f.read()
57
  except Exception as e:
58
- return f"Error reading {txt_path}: {e}"
 
 
59
 
60
  repo_id_input = gr.Textbox(label="Enter repo IDs (comma or newline separated)", lines=5, placeholder="repo1, repo2\nrepo3")
61
  df_output = gr.Dataframe(headers=["repo id", "strength", "weaknesses", "speciality", "relevance rating", "Usecase"])
@@ -69,8 +71,9 @@ with gr.Blocks() as demo:
69
 
70
  gr.Markdown("---")
71
  gr.Markdown("## Combine and Display Repo Files")
72
- combine_btn = gr.Button("Download, Combine & Show .py/.md Files from First Repo")
73
  combined_txt = gr.Textbox(label="Combined Repo Files", lines=20)
74
- combine_btn.click(show_combined_repo, inputs=None, outputs=combined_txt)
 
75
 
76
  demo.launch()
 
2
  import regex as re
3
  import csv
4
  import pandas as pd
5
+ from analyzer import combine_repo_files_for_llm, analyze_combined_file
6
  from hf_utils import download_space_repo
7
 
8
  # from hf_utils import download_space_repo
 
42
  df = pd.read_csv(csv_filename)
43
  return df
44
 
45
+ def show_combined_repo_and_llm():
46
  if not last_repo_ids:
47
+ return "No repo ID available. Please submit repo IDs first.", ""
48
  first_repo_id = last_repo_ids[0]
49
  try:
50
  download_space_repo(first_repo_id, local_dir="repo_files")
51
  except Exception as e:
52
+ return f"Error downloading repo: {e}", ""
53
  txt_path = combine_repo_files_for_llm()
54
  try:
55
  with open(txt_path, "r", encoding="utf-8") as f:
56
+ combined_content = f.read()
57
  except Exception as e:
58
+ return f"Error reading {txt_path}: {e}", ""
59
+ llm_output = analyze_combined_file(txt_path)
60
+ return combined_content, llm_output
61
 
62
  repo_id_input = gr.Textbox(label="Enter repo IDs (comma or newline separated)", lines=5, placeholder="repo1, repo2\nrepo3")
63
  df_output = gr.Dataframe(headers=["repo id", "strength", "weaknesses", "speciality", "relevance rating", "Usecase"])
 
71
 
72
  gr.Markdown("---")
73
  gr.Markdown("## Combine and Display Repo Files")
74
+ combine_btn = gr.Button("Download, Combine & Show .py/.md Files from First Repo and Analyze")
75
  combined_txt = gr.Textbox(label="Combined Repo Files", lines=20)
76
+ llm_output_txt = gr.Textbox(label="LLM Analysis Output", lines=10)
77
+ combine_btn.click(show_combined_repo_and_llm, inputs=None, outputs=[combined_txt, llm_output_txt])
78
 
79
  demo.launch()