Spaces:
Paused
Paused
Upload folder using huggingface_hub
Browse files
app.py
CHANGED
|
@@ -160,6 +160,14 @@ POOL_PATH = "PersonaPool"
|
|
| 160 |
# Global state for processed reports
|
| 161 |
processed_prs = set()
|
| 162 |
all_discovered_reports = ""
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 163 |
|
| 164 |
# Helper for parallel LLM calls
|
| 165 |
def call_llm_parallel(client, model_names, messages, **kwargs):
|
|
@@ -199,58 +207,69 @@ def get_blablador_client():
|
|
| 199 |
base_url=BLABLADOR_BASE_URL
|
| 200 |
)
|
| 201 |
|
| 202 |
-
def get_user_repos():
|
| 203 |
-
|
| 204 |
-
|
| 205 |
-
|
|
|
|
| 206 |
return ["JsonLord/tiny_web"]
|
| 207 |
try:
|
| 208 |
-
user =
|
| 209 |
repos = [repo.full_name for repo in user.get_repos()]
|
| 210 |
-
|
| 211 |
if "JsonLord/tiny_web" not in repos:
|
| 212 |
repos.append("JsonLord/tiny_web")
|
| 213 |
return sorted(repos)
|
| 214 |
except Exception as e:
|
| 215 |
-
|
| 216 |
return ["JsonLord/tiny_web"]
|
| 217 |
|
| 218 |
-
def get_repo_branches(repo_full_name):
|
| 219 |
-
|
| 220 |
-
|
| 221 |
-
|
|
|
|
| 222 |
return ["main"]
|
| 223 |
if not repo_full_name:
|
| 224 |
return ["main"]
|
| 225 |
try:
|
| 226 |
-
repo =
|
| 227 |
-
# Fetch branches
|
| 228 |
-
|
| 229 |
-
|
| 230 |
-
for i, b in enumerate(branches_paginated):
|
| 231 |
-
if i >= 100: break
|
| 232 |
-
branches_list.append(b)
|
| 233 |
-
|
| 234 |
-
print(f"DEBUG: Found {len(branches_list)} branches (limited to 100). Names: {[b.name for b in branches_list]}")
|
| 235 |
|
| 236 |
-
#
|
| 237 |
branch_info = []
|
| 238 |
-
|
|
|
|
| 239 |
try:
|
| 240 |
commit = repo.get_commit(b.commit.sha)
|
| 241 |
-
|
| 242 |
-
|
| 243 |
-
|
| 244 |
-
|
| 245 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 246 |
|
| 247 |
# Sort by date descending
|
| 248 |
branch_info.sort(key=lambda x: x[1], reverse=True)
|
| 249 |
result = [b[0] for b in branch_info]
|
| 250 |
-
|
|
|
|
|
|
|
|
|
|
| 251 |
return result
|
| 252 |
except Exception as e:
|
| 253 |
-
|
| 254 |
import traceback
|
| 255 |
traceback.print_exc()
|
| 256 |
return ["main"]
|
|
@@ -792,14 +811,61 @@ with gr.Blocks() as demo:
|
|
| 792 |
sl_branch_select.change(fn=sl_update_reports, inputs=[sl_repo_select, sl_branch_select], outputs=[sl_report_select])
|
| 793 |
sl_render_btn.click(fn=render_slides, inputs=[sl_repo_select, sl_branch_select, sl_report_select], outputs=[slideshow_display])
|
| 794 |
|
| 795 |
-
with gr.Tab("
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 796 |
gr.Markdown("### Live Monitoring of JsonLord/tiny_web for new UX reports")
|
|
|
|
| 797 |
refresh_feed_btn = gr.Button("Refresh Feed Now")
|
| 798 |
global_feed = gr.Markdown(value="Waiting for new reports...")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 799 |
# Use a Timer to poll every 60 seconds
|
| 800 |
timer = gr.Timer(value=60)
|
| 801 |
-
timer.tick(fn=
|
| 802 |
-
refresh_feed_btn.click(fn=
|
| 803 |
|
| 804 |
# Event handlers
|
| 805 |
generate_btn.click(
|
|
|
|
| 160 |
# Global state for processed reports
|
| 161 |
processed_prs = set()
|
| 162 |
all_discovered_reports = ""
|
| 163 |
+
github_logs = []
|
| 164 |
+
|
| 165 |
+
def add_log(message):
|
| 166 |
+
timestamp = datetime.now().strftime("%H:%M:%S")
|
| 167 |
+
log_entry = f"[{timestamp}] {message}"
|
| 168 |
+
github_logs.append(log_entry)
|
| 169 |
+
print(log_entry)
|
| 170 |
+
return "\n".join(github_logs[-20:])
|
| 171 |
|
| 172 |
# Helper for parallel LLM calls
|
| 173 |
def call_llm_parallel(client, model_names, messages, **kwargs):
|
|
|
|
| 207 |
base_url=BLABLADOR_BASE_URL
|
| 208 |
)
|
| 209 |
|
| 210 |
+
def get_user_repos(github_client=None):
|
| 211 |
+
client = github_client or gh
|
| 212 |
+
add_log("Fetching user repositories...")
|
| 213 |
+
if not client:
|
| 214 |
+
add_log("ERROR: GitHub client not initialized.")
|
| 215 |
return ["JsonLord/tiny_web"]
|
| 216 |
try:
|
| 217 |
+
user = client.get_user()
|
| 218 |
repos = [repo.full_name for repo in user.get_repos()]
|
| 219 |
+
add_log(f"Found {len(repos)} repositories.")
|
| 220 |
if "JsonLord/tiny_web" not in repos:
|
| 221 |
repos.append("JsonLord/tiny_web")
|
| 222 |
return sorted(repos)
|
| 223 |
except Exception as e:
|
| 224 |
+
add_log(f"ERROR fetching repos: {e}")
|
| 225 |
return ["JsonLord/tiny_web"]
|
| 226 |
|
| 227 |
+
def get_repo_branches(repo_full_name, github_client=None):
|
| 228 |
+
client = github_client or gh
|
| 229 |
+
add_log(f"Fetching branches for {repo_full_name}...")
|
| 230 |
+
if not client:
|
| 231 |
+
add_log("ERROR: GitHub client is None.")
|
| 232 |
return ["main"]
|
| 233 |
if not repo_full_name:
|
| 234 |
return ["main"]
|
| 235 |
try:
|
| 236 |
+
repo = client.get_repo(repo_full_name)
|
| 237 |
+
# Fetch branches
|
| 238 |
+
branches = list(repo.get_branches())
|
| 239 |
+
add_log(f"Discovered {len(branches)} branches.")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 240 |
|
| 241 |
+
# Use ThreadPool to fetch commit dates in parallel to be MUCH faster
|
| 242 |
branch_info = []
|
| 243 |
+
|
| 244 |
+
def fetch_branch_date(b):
|
| 245 |
try:
|
| 246 |
commit = repo.get_commit(b.commit.sha)
|
| 247 |
+
# Try multiple ways to get the date
|
| 248 |
+
date = None
|
| 249 |
+
if commit.commit and commit.commit.author:
|
| 250 |
+
date = commit.commit.author.date
|
| 251 |
+
elif commit.commit and commit.commit.committer:
|
| 252 |
+
date = commit.commit.committer.date
|
| 253 |
+
|
| 254 |
+
if not date:
|
| 255 |
+
date = datetime.min
|
| 256 |
+
return (b.name, date)
|
| 257 |
+
except Exception as e:
|
| 258 |
+
return (b.name, datetime.min)
|
| 259 |
+
|
| 260 |
+
with concurrent.futures.ThreadPoolExecutor(max_workers=20) as executor:
|
| 261 |
+
branch_info = list(executor.map(fetch_branch_date, branches))
|
| 262 |
|
| 263 |
# Sort by date descending
|
| 264 |
branch_info.sort(key=lambda x: x[1], reverse=True)
|
| 265 |
result = [b[0] for b in branch_info]
|
| 266 |
+
|
| 267 |
+
if result:
|
| 268 |
+
add_log(f"Successfully sorted {len(result)} branches. Latest: {result[0]}")
|
| 269 |
+
|
| 270 |
return result
|
| 271 |
except Exception as e:
|
| 272 |
+
add_log(f"ERROR fetching branches: {e}")
|
| 273 |
import traceback
|
| 274 |
traceback.print_exc()
|
| 275 |
return ["main"]
|
|
|
|
| 811 |
sl_branch_select.change(fn=sl_update_reports, inputs=[sl_repo_select, sl_branch_select], outputs=[sl_report_select])
|
| 812 |
sl_render_btn.click(fn=render_slides, inputs=[sl_repo_select, sl_branch_select, sl_report_select], outputs=[slideshow_display])
|
| 813 |
|
| 814 |
+
with gr.Tab("System"):
|
| 815 |
+
gr.Markdown("### System Diagnostics & Manual Connection")
|
| 816 |
+
with gr.Row():
|
| 817 |
+
sys_token_input = gr.Textbox(label="GitHub Token (Leave blank for default)", type="password")
|
| 818 |
+
sys_repo_input = gr.Textbox(label="Repository (e.g., JsonLord/tiny_web)", value=REPO_NAME)
|
| 819 |
+
sys_test_btn = gr.Button("Test Connection & Fetch Branches")
|
| 820 |
+
|
| 821 |
+
sys_status = gr.Textbox(label="Connection Status", interactive=False)
|
| 822 |
+
sys_branch_output = gr.JSON(label="Discovered Branches")
|
| 823 |
+
|
| 824 |
+
def system_test(token, repo_name):
|
| 825 |
+
try:
|
| 826 |
+
test_gh = Github(token) if token else gh
|
| 827 |
+
if not test_gh:
|
| 828 |
+
return "Error: No GitHub client available.", None
|
| 829 |
+
|
| 830 |
+
user = test_gh.get_user().login
|
| 831 |
+
status = f"Success: Connected as {user} to {repo_name}"
|
| 832 |
+
|
| 833 |
+
# Fetch all branches with dates
|
| 834 |
+
repo = test_gh.get_repo(repo_name)
|
| 835 |
+
branches = list(repo.get_branches())
|
| 836 |
+
branch_details = []
|
| 837 |
+
for b in branches:
|
| 838 |
+
try:
|
| 839 |
+
commit = repo.get_commit(b.commit.sha)
|
| 840 |
+
date = commit.commit.author.date.isoformat()
|
| 841 |
+
branch_details.append({"name": b.name, "last_commit": date, "sha": b.commit.sha})
|
| 842 |
+
except:
|
| 843 |
+
branch_details.append({"name": b.name, "last_commit": "Unknown", "sha": b.commit.sha})
|
| 844 |
+
|
| 845 |
+
# Sort by date
|
| 846 |
+
branch_details.sort(key=lambda x: x["last_commit"], reverse=True)
|
| 847 |
+
|
| 848 |
+
return status, branch_details
|
| 849 |
+
except Exception as e:
|
| 850 |
+
return f"Error: {str(e)}", None
|
| 851 |
+
|
| 852 |
+
sys_test_btn.click(fn=system_test, inputs=[sys_token_input, sys_repo_input], outputs=[sys_status, sys_branch_output])
|
| 853 |
+
|
| 854 |
+
with gr.Tab("Live Monitoring"):
|
| 855 |
gr.Markdown("### Live Monitoring of JsonLord/tiny_web for new UX reports")
|
| 856 |
+
live_log = gr.Textbox(label="GitHub Connection Logs", lines=5, interactive=False)
|
| 857 |
refresh_feed_btn = gr.Button("Refresh Feed Now")
|
| 858 |
global_feed = gr.Markdown(value="Waiting for new reports...")
|
| 859 |
+
|
| 860 |
+
def monitor_and_log():
|
| 861 |
+
reports = monitor_repo_for_reports()
|
| 862 |
+
logs = "\n".join(github_logs[-20:])
|
| 863 |
+
return reports, logs
|
| 864 |
+
|
| 865 |
# Use a Timer to poll every 60 seconds
|
| 866 |
timer = gr.Timer(value=60)
|
| 867 |
+
timer.tick(fn=monitor_and_log, outputs=[global_feed, live_log])
|
| 868 |
+
refresh_feed_btn.click(fn=monitor_and_log, outputs=[global_feed, live_log])
|
| 869 |
|
| 870 |
# Event handlers
|
| 871 |
generate_btn.click(
|