import json,time,threading,requests import gradio as gr WORKER_URL='https://Nottybro-pmc-worker.hf.space' POLL_SECS=30 all_sessions={};wh={'last_ok':None,'failures':0};state_lock=threading.Lock() def poll(): while True: for endpoint,method in [ (f'{WORKER_URL}/api/get_status','post'), (f'{WORKER_URL}/api/status','post'), ]: try: r=requests.post(endpoint,json={'data':[]},timeout=25) r.raise_for_status() raw=r.json() payload=raw.get('data',[None])[0] if isinstance(raw,dict) and 'data' in raw else raw parsed=json.loads(payload) if isinstance(payload,str) else payload with state_lock: all_sessions.update(parsed) wh['last_ok']=time.strftime('%H:%M:%S UTC',time.gmtime()) wh['failures']=0 break except Exception as e: print(f'Poll {endpoint}: {e}') continue else: with state_lock: wh['failures']+=1 time.sleep(POLL_SECS) threading.Thread(target=poll,daemon=True).start() BADGE={'idle':'⚪','pushing':'🔄','queued':'🟡','inQueue':'🟡', 'running':'🟢','complete':'✅','done':'🏁','error':'🔴', 'push_failed':'🔴','not_found':'⏳'} def _b(st): for k,v in BADGE.items(): if k in st: return f'{v} {st}' return st def sess_table(): with state_lock: if not all_sessions: return [['Waiting for worker...']] return [[s['session_id'],s.get('username','')[:14],_b(s.get('status','?')), s.get('run_number',0),s.get('success',0), f'{s.get("current_idx",0)}/{s.get("total_builds",0)}', (s.get('kernel_url') or '-')[:55],(s.get('last_check') or '-')[-8:]] for _,s in sorted(all_sessions.items(),key=lambda x:int(x[0]))] def summary(): with state_lock: if not all_sessions: return '⏳ Waiting...' vals=list(all_sessions.values()) done=sum(1 for s in vals if s.get('complete')) run=sum(1 for s in vals if 'running' in s.get('status','')) q=sum(1 for s in vals if 'queue' in s.get('status','').lower()) ok=sum(s.get('success',0) for s in vals) total=sum(s.get('total_builds',0) for s in vals) curr=sum(s.get('current_idx',0) for s in vals) pct=round(curr/max(total,1)*100,1) bar='X'*int(pct/5)+'.'*(20-int(pct/5)) last=wh['last_ok'] or 'never' cf=wh['failures'] return (f'### PMC Master\n[{bar}] {pct}% | **{ok:,} builds** | ' f'{done}/15 done | {run} running | {q} queued\n' f'Worker: `{last}` | {"⚠️ UNREACHABLE" if cf>=3 else "✅ OK"}') def all_links(): with state_lock: lines=[] for _,s in sorted(all_sessions.items(),key=lambda x:int(x[0])): for h in s.get('history',[]): lines.append(f's{s["session_id"]} r{h["run_number"]} idx={h.get("start_idx","?")} | {h["url"]}') return '\n'.join(lines) or 'No data yet.' R=30 with gr.Blocks(title='PMC Master') as demo: gr.Markdown('# PMC Master Dashboard') gr.Markdown(value=summary,every=R) gr.Dataframe(headers=['Sess','Account','Status','Runs','Built', 'Progress','Kernel URL','Last check'], value=sess_table,every=R,interactive=False,wrap=True) with gr.Tabs(): with gr.Tab('All links'): gr.Textbox(value=all_links,every=R,lines=40,interactive=False,label='All kernel URLs') gr.Markdown(f'Worker: [https://Nottybro-pmc-worker.hf.space](https://Nottybro-pmc-worker.hf.space)') demo.queue() demo.launch()