Update app.py
Browse files
app.py
CHANGED
@@ -86,14 +86,25 @@ def create_ui() -> gr.Blocks:
|
|
86 |
|
87 |
with gr.Row():
|
88 |
with gr.Column():
|
89 |
-
# Input Section
|
90 |
-
gr.Markdown("### Enter Repository
|
91 |
-
|
92 |
-
label="Enter
|
93 |
-
lines=
|
94 |
-
placeholder="
|
95 |
)
|
96 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
97 |
status = gr.Textbox(label="Status", visible=True)
|
98 |
|
99 |
# Results Section
|
@@ -117,25 +128,46 @@ def create_ui() -> gr.Blocks:
|
|
117 |
send_btn = gr.Button("Send", variant="primary")
|
118 |
clear_btn = gr.Button("Clear Chat", variant="secondary")
|
119 |
|
120 |
-
def
|
121 |
-
"""Process
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
122 |
try:
|
123 |
-
|
124 |
-
|
125 |
-
|
126 |
-
|
127 |
-
|
128 |
-
|
129 |
-
|
130 |
-
|
131 |
-
# Handle as repo IDs
|
132 |
-
repo_ids = [rid.strip() for rid in re.split(r'[\n,]+', text) if rid.strip()]
|
133 |
|
134 |
# Remove duplicates
|
135 |
repo_ids = list(dict.fromkeys(repo_ids))
|
136 |
|
137 |
if not repo_ids:
|
138 |
-
return pd.DataFrame(), "No repositories found", "", ""
|
139 |
|
140 |
# Update CSV
|
141 |
write_repos_to_csv(repo_ids)
|
@@ -146,7 +178,7 @@ def create_ui() -> gr.Blocks:
|
|
146 |
return read_csv_as_text(CSV_FILE), f"Found {len(repo_ids)} repositories", content, summary
|
147 |
|
148 |
except Exception as e:
|
149 |
-
logger.error(f"Error processing
|
150 |
return pd.DataFrame(), f"Error: {str(e)}", "", ""
|
151 |
|
152 |
def send_message(message: str, history: List[Dict[str, str]]) -> Tuple[List[Dict[str, str]], str]:
|
@@ -163,9 +195,15 @@ def create_ui() -> gr.Blocks:
|
|
163 |
return [], ""
|
164 |
|
165 |
# Event handlers
|
166 |
-
|
167 |
-
fn=
|
168 |
-
inputs=[
|
|
|
|
|
|
|
|
|
|
|
|
|
169 |
outputs=[df_output, status, content_output, summary_output]
|
170 |
)
|
171 |
|
|
|
86 |
|
87 |
with gr.Row():
|
88 |
with gr.Column():
|
89 |
+
# Repository ID Input Section
|
90 |
+
gr.Markdown("### Enter Repository IDs")
|
91 |
+
repo_id_input = gr.Textbox(
|
92 |
+
label="Enter repository IDs (comma or newline separated)",
|
93 |
+
lines=3,
|
94 |
+
placeholder="repo1, repo2\nrepo3"
|
95 |
)
|
96 |
+
submit_repo_btn = gr.Button("Submit Repository IDs", variant="primary")
|
97 |
+
|
98 |
+
# Keyword Search Section
|
99 |
+
gr.Markdown("### Or Search by Keywords")
|
100 |
+
keyword_input = gr.Textbox(
|
101 |
+
label="Enter keywords to search",
|
102 |
+
lines=2,
|
103 |
+
placeholder="Enter keywords separated by commas"
|
104 |
+
)
|
105 |
+
search_btn = gr.Button("Search by Keywords", variant="primary")
|
106 |
+
|
107 |
+
# Status
|
108 |
status = gr.Textbox(label="Status", visible=True)
|
109 |
|
110 |
# Results Section
|
|
|
128 |
send_btn = gr.Button("Send", variant="primary")
|
129 |
clear_btn = gr.Button("Clear Chat", variant="secondary")
|
130 |
|
131 |
+
def process_repo_ids(text: str) -> Tuple[pd.DataFrame, str, str, str]:
|
132 |
+
"""Process repository IDs and return results."""
|
133 |
+
try:
|
134 |
+
repo_ids = [rid.strip() for rid in re.split(r'[\n,]+', text) if rid.strip()]
|
135 |
+
|
136 |
+
if not repo_ids:
|
137 |
+
return pd.DataFrame(), "No repository IDs provided", "", ""
|
138 |
+
|
139 |
+
# Remove duplicates
|
140 |
+
repo_ids = list(dict.fromkeys(repo_ids))
|
141 |
+
|
142 |
+
# Update CSV
|
143 |
+
write_repos_to_csv(repo_ids)
|
144 |
+
|
145 |
+
# Get first repo analysis
|
146 |
+
content, summary = analyze_repo(repo_ids[0])
|
147 |
+
|
148 |
+
return read_csv_as_text(CSV_FILE), f"Found {len(repo_ids)} repositories", content, summary
|
149 |
+
|
150 |
+
except Exception as e:
|
151 |
+
logger.error(f"Error processing repository IDs: {e}")
|
152 |
+
return pd.DataFrame(), f"Error: {str(e)}", "", ""
|
153 |
+
|
154 |
+
def process_keywords(text: str) -> Tuple[pd.DataFrame, str, str, str]:
|
155 |
+
"""Process keywords and return search results."""
|
156 |
try:
|
157 |
+
keywords = [k.strip() for k in re.split(r'[\n,]+', text) if k.strip()]
|
158 |
+
|
159 |
+
if not keywords:
|
160 |
+
return pd.DataFrame(), "No keywords provided", "", ""
|
161 |
+
|
162 |
+
repo_ids = []
|
163 |
+
for kw in keywords:
|
164 |
+
repo_ids.extend(search_top_spaces(kw, limit=5))
|
|
|
|
|
165 |
|
166 |
# Remove duplicates
|
167 |
repo_ids = list(dict.fromkeys(repo_ids))
|
168 |
|
169 |
if not repo_ids:
|
170 |
+
return pd.DataFrame(), "No repositories found for the given keywords", "", ""
|
171 |
|
172 |
# Update CSV
|
173 |
write_repos_to_csv(repo_ids)
|
|
|
178 |
return read_csv_as_text(CSV_FILE), f"Found {len(repo_ids)} repositories", content, summary
|
179 |
|
180 |
except Exception as e:
|
181 |
+
logger.error(f"Error processing keywords: {e}")
|
182 |
return pd.DataFrame(), f"Error: {str(e)}", "", ""
|
183 |
|
184 |
def send_message(message: str, history: List[Dict[str, str]]) -> Tuple[List[Dict[str, str]], str]:
|
|
|
195 |
return [], ""
|
196 |
|
197 |
# Event handlers
|
198 |
+
submit_repo_btn.click(
|
199 |
+
fn=process_repo_ids,
|
200 |
+
inputs=[repo_id_input],
|
201 |
+
outputs=[df_output, status, content_output, summary_output]
|
202 |
+
)
|
203 |
+
|
204 |
+
search_btn.click(
|
205 |
+
fn=process_keywords,
|
206 |
+
inputs=[keyword_input],
|
207 |
outputs=[df_output, status, content_output, summary_output]
|
208 |
)
|
209 |
|