Spaces:
Paused
Paused
File size: 3,189 Bytes
1ecb7e5 b388064 1ecb7e5 f8ebd62 3a28857 f8ebd62 1ecb7e5 f8ebd62 1ecb7e5 f8ebd62 1ecb7e5 f8ebd62 187d33a 1ecb7e5 187d33a 1ecb7e5 187d33a 1dfe30e 187d33a 1dfe30e 187d33a f8ebd62 187d33a f8ebd62 1dfe30e | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 | _A='replace'
import re
from pathlib import Path
import gradio as gr
from services.minecraft_service import MC_DIR
LOG_DIR=Path('/home/user/.torch_metrics')
MC_LOG=Path(MC_DIR)/'logs'/'latest.log'
ANSI=re.compile('\\x1B(?:[@-Z\\\\-_]|\\[[0-?]*[ -/]*[@-~])')
_LOG_CMDS={'SHOW_LOGS_TAILSCALE':(f"{LOG_DIR}/ts_daemon.log",'TAILSCALE LOGS'),'SHOW_LOGS_FILEBROWSER':(f"{LOG_DIR}/fb.log",'FILEBROWSER LOGS'),'SHOW_LOGS_METRICS2':(f"{LOG_DIR}/tm_daemon.log",'METRICS LOGS',True),'SHOW_LOGS_STARTUP':(f"{LOG_DIR}/startup.log",'STARTUP LOGS'),'SHOW_LOGS_CHISEL':(f"{LOG_DIR}/chisel.log",'CHISEL LOGS'),'SHOW_LOGS_GOST':(f"{LOG_DIR}/gost.log",'GOST LOGS'),'SHOW_LOGS_LIGOLO':(f"{LOG_DIR}/ligolo.log",'LIGOLO LOGS'),'SHOW_LOGS_SLIVER':(f"{LOG_DIR}/sliver.log",'SLIVER LOGS'),'SHOW_LOGS_CADDY':(f"{LOG_DIR}/caddy.log",'CADDY LOGS'),'SHOW_LOGS_TEST':(f"{LOG_DIR}/test.log",'TEST SERVICE LOGS'),'SHOW_LOGS_LLM_PROXY':(f"{LOG_DIR}/llm_proxy.log",'LLM PROXY LOGS'),'SHOW_LOGS_OPEN_WEBUI':(f"{LOG_DIR}/open_webui.log",'OPEN WEBUI LOGS'),'SHOW_LOGS_CODE_SERVER':(f"{LOG_DIR}/code_server.log",'CODE SERVER LOGS')}
def _read_log(path,label,strip_ansi=False):
try:
with Path(path).open(errors=_A)as A:B=ANSI.sub('',A.read())if strip_ansi else A.read()
return f"{label}:\n{B}"
except Exception as C:return f"Log error: {C}"
def _read_mc_log():
try:
if not MC_LOG.exists():return'Minecraft latest.log not found yet.'
with MC_LOG.open(errors=_A)as A:return f"=== Minecraft latest.log ===\n{A.read()}"
except Exception as B:return f"Log error: {B}"
def _read_all_logs():
try:
A=[]
for B in sorted(LOG_DIR.iterdir()):
if B.is_file()and B.suffix=='.log':
with B.open(errors=_A)as C:A.append(f"=== {B.name} ===\n{C.read()}\n")
if MC_LOG.exists():
with MC_LOG.open(errors=_A)as C:A.append(f"=== Minecraft latest.log ===\n{C.read()}\n")
return'\n'.join(A)if A else'No logs found.'
except Exception as D:return f"Log error: {D}"
def _read_api_stats():
M='==========================================';L='MODEL:';K='KEY:';F=LOG_DIR/'api_calls.txt'
if not F.exists():return'No API calls logged yet.'
try:
with F.open(errors=_A)as N:G=N.readlines()
C={};D={}
for B in G:
if K in B and L in B:H=B.split('|');I=H[0].split(K)[1].strip();J=H[1].split(L)[1].strip();C[I]=C.get(I,0)+1;D[J]=D.get(J,0)+1
A=[M,' LOCAL API CALL STATISTICS ',M,'\n[CALLS PER VIRTUAL KEY]']
for(O,E)in sorted(C.items(),key=lambda x:x[1],reverse=True):A.append(f" - {O}: {E} calls")
A.append('\n[CALLS PER MODEL]')
for(P,E)in sorted(D.items(),key=lambda x:x[1],reverse=True):A.append(f" - {P}: {E} calls")
A.append('\n[RECENT ACTIVITY (LAST 5 CALLS)]')
for B in G[-5:]:A.append(' '+B.strip())
return'\n'.join(A)
except Exception as Q:return f"Error reading stats: {Q}"
def fake_model(text):
A=text.strip()
if A=='SHOW_ALL_LOGS':return _read_all_logs()
if A=='SHOW_LOGS_MC':return _read_mc_log()
if A=='SHOW_API_STATS':return _read_api_stats()
B=_LOG_CMDS.get(A)
if B:return _read_log(*B)
return f"Model processed: {text}"
gr.Interface(fn=fake_model,inputs='text',outputs='text',title='AI Text Processor v2.1').launch(server_name='127.0.0.1',server_port=7861,root_path='') |