naman1102 commited on
Commit
3414412
·
1 Parent(s): 1a943f1

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +26 -13
app.py CHANGED
@@ -23,16 +23,19 @@ def process_repo_input(text):
23
  df = pd.read_csv(csv_filename)
24
  return df
25
 
26
- # Store the last entered repo ids in a global variable for button access
27
  last_repo_ids = []
 
28
 
29
  def process_repo_input_and_store(text):
30
- global last_repo_ids
31
  if not text:
32
  last_repo_ids = []
 
33
  return pd.DataFrame(columns=["repo id", "strength", "weaknesses", "speciality", "relevance rating"])
34
  repo_ids = [repo.strip() for repo in re.split(r'[\n,]+', text) if repo.strip()]
35
  last_repo_ids = repo_ids
 
36
  csv_filename = "repo_ids.csv"
37
  with open(csv_filename, mode="w", newline='', encoding="utf-8") as csvfile:
38
  writer = csv.writer(csvfile)
@@ -43,27 +46,32 @@ def process_repo_input_and_store(text):
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
  llm_json = parse_llm_json_response(llm_output)
61
- # Update CSV for the first repo id
62
  csv_filename = "repo_ids.csv"
63
  try:
64
  df = pd.read_csv(csv_filename)
 
65
  for idx, row in df.iterrows():
66
- if row["repo id"] == first_repo_id:
 
67
  if isinstance(llm_json, dict):
68
  df.at[idx, "strength"] = llm_json.get("strength", "")
69
  df.at[idx, "weaknesses"] = llm_json.get("weaknesses", "")
@@ -72,8 +80,11 @@ def show_combined_repo_and_llm():
72
  break
73
  df.to_csv(csv_filename, index=False)
74
  except Exception as e:
75
- pass # Optionally log error
76
- return combined_content, llm_output
 
 
 
77
 
78
  repo_id_input = gr.Textbox(label="Enter repo IDs (comma or newline separated)", lines=5, placeholder="repo1, repo2\nrepo3")
79
  df_output = gr.Dataframe(headers=["repo id", "strength", "weaknesses", "speciality", "relevance rating", "Usecase"])
@@ -87,9 +98,11 @@ with gr.Blocks() as demo:
87
 
88
  gr.Markdown("---")
89
  gr.Markdown("## Combine and Display Repo Files")
90
- combine_btn = gr.Button("Download, Combine & Show .py/.md Files from First Repo and Analyze")
91
  combined_txt = gr.Textbox(label="Combined Repo Files", lines=20)
92
  llm_output_txt = gr.Textbox(label="LLM Analysis Output", lines=10)
93
- combine_btn.click(show_combined_repo_and_llm, inputs=None, outputs=[combined_txt, llm_output_txt])
 
 
94
 
95
  demo.launch()
 
23
  df = pd.read_csv(csv_filename)
24
  return df
25
 
26
+ # Store the last entered repo ids and the current index in global variables for button access
27
  last_repo_ids = []
28
+ current_repo_idx = 0
29
 
30
  def process_repo_input_and_store(text):
31
+ global last_repo_ids, current_repo_idx
32
  if not text:
33
  last_repo_ids = []
34
+ current_repo_idx = 0
35
  return pd.DataFrame(columns=["repo id", "strength", "weaknesses", "speciality", "relevance rating"])
36
  repo_ids = [repo.strip() for repo in re.split(r'[\n,]+', text) if repo.strip()]
37
  last_repo_ids = repo_ids
38
+ current_repo_idx = 0
39
  csv_filename = "repo_ids.csv"
40
  with open(csv_filename, mode="w", newline='', encoding="utf-8") as csvfile:
41
  writer = csv.writer(csvfile)
 
46
  return df
47
 
48
  def show_combined_repo_and_llm():
49
+ global current_repo_idx
50
  if not last_repo_ids:
51
+ return "No repo ID available. Please submit repo IDs first.", "", pd.DataFrame(), None
52
+ if current_repo_idx >= len(last_repo_ids):
53
+ return "All repo IDs have been processed.", "", pd.read_csv("repo_ids.csv"), None
54
+ repo_id = last_repo_ids[current_repo_idx]
55
  try:
56
+ download_space_repo(repo_id, local_dir="repo_files")
57
  except Exception as e:
58
+ return f"Error downloading repo: {e}", "", pd.read_csv("repo_ids.csv"), None
59
  txt_path = combine_repo_files_for_llm()
60
  try:
61
  with open(txt_path, "r", encoding="utf-8") as f:
62
  combined_content = f.read()
63
  except Exception as e:
64
+ return f"Error reading {txt_path}: {e}", "", pd.read_csv("repo_ids.csv"), None
65
  llm_output = analyze_combined_file(txt_path)
66
  llm_json = parse_llm_json_response(llm_output)
67
+ # Update CSV for the current repo id
68
  csv_filename = "repo_ids.csv"
69
  try:
70
  df = pd.read_csv(csv_filename)
71
+ highlight_idx = None
72
  for idx, row in df.iterrows():
73
+ if row["repo id"] == repo_id:
74
+ highlight_idx = idx
75
  if isinstance(llm_json, dict):
76
  df.at[idx, "strength"] = llm_json.get("strength", "")
77
  df.at[idx, "weaknesses"] = llm_json.get("weaknesses", "")
 
80
  break
81
  df.to_csv(csv_filename, index=False)
82
  except Exception as e:
83
+ df = pd.read_csv(csv_filename)
84
+ highlight_idx = None
85
+ # Move to next repo for next click
86
+ current_repo_idx += 1
87
+ return combined_content, llm_output, df, highlight_idx
88
 
89
  repo_id_input = gr.Textbox(label="Enter repo IDs (comma or newline separated)", lines=5, placeholder="repo1, repo2\nrepo3")
90
  df_output = gr.Dataframe(headers=["repo id", "strength", "weaknesses", "speciality", "relevance rating", "Usecase"])
 
98
 
99
  gr.Markdown("---")
100
  gr.Markdown("## Combine and Display Repo Files")
101
+ combine_btn = gr.Button("Download, Combine & Show .py/.md Files from Next Repo and Analyze")
102
  combined_txt = gr.Textbox(label="Combined Repo Files", lines=20)
103
  llm_output_txt = gr.Textbox(label="LLM Analysis Output", lines=10)
104
+ df_display = gr.Dataframe(headers=["repo id", "strength", "weaknesses", "speciality", "relevance rating", "Usecase"])
105
+ highlight_row = gr.HighlightedText(label="Highlighted Row Index")
106
+ combine_btn.click(show_combined_repo_and_llm, inputs=None, outputs=[combined_txt, llm_output_txt, df_display, highlight_row])
107
 
108
  demo.launch()