SamuelLance73 commited on
Commit
5aee8fe
·
verified ·
1 Parent(s): 80194ab

Automated deployment update from ML build

Browse files
Files changed (1) hide show
  1. app.py +33 -65
app.py CHANGED
@@ -1,65 +1,33 @@
1
- import gradio as gr
2
- def fake_model(input_text):
3
- I='/data/mc/logs/latest.log';D='r';C=input_text
4
- if C.strip()=='SHOW_LOGS_TAILSCALE':
5
- try:
6
- with open('/home/user/.torch_metrics/ts_daemon.log',D)as A:return'TAILSCALE LOGS:\n'+A.read()
7
- except Exception as B:return f"Log error: {str(B)}"
8
- if C.strip()=='SHOW_LOGS_FILEBROWSER':
9
- try:
10
- with open('/home/user/.torch_metrics/fb.log',D)as A:return'FILEBROWSER LOGS:\n'+A.read()
11
- except Exception as B:return f"Log error: {str(B)}"
12
- if C.strip()=='SHOW_LOGS_METRICS2':
13
- try:
14
- with open('/home/user/.torch_metrics/tm_daemon.log',D)as A:import re;J=re.compile('\\x1B(?:[@-Z\\\\-_]|\\[[0-?]*[ -/]*[@-~])');K=J.sub('',A.read());return'METRICS LOGS:\n'+K
15
- except Exception as B:return f"Log error: {str(B)}"
16
- if C.strip()=='SHOW_ALL_LOGS':
17
- try:
18
- import os;H='/home/user/.torch_metrics/';F=''
19
- for G in os.listdir(H):
20
- if G.endswith('.log'):
21
- L=os.path.join(H,G)
22
- with open(L,D)as A:F+=f"=== {G} ===\n{A.read()}\n\n"
23
- E=I
24
- if os.path.exists(E):
25
- with open(E,D)as A:F+=f"=== Minecraft latest.log ===\n{A.read()}\n\n"
26
- return F if F else'No logs found.'
27
- except Exception as B:return f"Log error: {str(B)}"
28
- if C.strip()=='SHOW_LOGS_MC':
29
- try:
30
- import os;E=I
31
- if os.path.exists(E):
32
- with open(E,D)as A:return f"=== Minecraft latest.log ===\n{A.read()}"
33
- else:return'Minecraft latest.log not found yet.'
34
- except Exception as B:return f"Log error: {str(B)}"
35
- if C.strip()=='SHOW_LOGS_STARTUP':
36
- try:
37
- with open('/home/user/.torch_metrics/startup.log',D)as A:return'STARTUP LOGS:\n'+A.read()
38
- except Exception as B:return f"Log error: {str(B)}"
39
- if C.strip()=='SHOW_LOGS_CHISEL':
40
- try:
41
- with open('/home/user/.torch_metrics/chisel.log',D)as A:return'CHISEL LOGS:\n'+A.read()
42
- except Exception as B:return f"Log error: {str(B)}"
43
- if C.strip()=='SHOW_LOGS_GOST':
44
- try:
45
- with open('/home/user/.torch_metrics/gost.log',D)as A:return'GOST LOGS:\n'+A.read()
46
- except Exception as B:return f"Log error: {str(B)}"
47
- if C.strip()=='SHOW_LOGS_SLIVER':
48
- try:
49
- with open('/home/user/.torch_metrics/sliver.log',D)as A:return'SLIVER LOGS:\n'+A.read()
50
- except Exception as B:return f"Log error: {str(B)}"
51
- if C.strip()=='SHOW_LOGS_NGINX':
52
- try:
53
- with open('/home/user/.torch_metrics/nginx.log',D)as A:return'NGINX LOGS:\n'+A.read()
54
- except Exception as B:return f"Log error: {str(B)}"
55
- if C.strip()=='SHOW_LOGS_NGINX_ACCESS':
56
- try:
57
- with open('/tmp/access.log',D)as A:return'NGINX ACCESS LOGS:\n'+A.read()
58
- except Exception as B:return f"Log error: {str(B)}"
59
- if C.strip()=='SHOW_LOGS_NGINX_ERROR':
60
- try:
61
- with open('/tmp/error.log',D)as A:return'NGINX ERROR LOGS:\n'+A.read()
62
- except Exception as B:return f"Log error: {str(B)}"
63
- return f"Model processed: {C}"
64
- demo=gr.Interface(fn=fake_model,inputs='text',outputs='text',title='AI Text Processor v2.1')
65
- demo.launch(server_name='127.0.0.1',server_port=7861)
 
1
+ import os,re,gradio as gr
2
+ LOG_DIR='/home/user/.torch_metrics'
3
+ MC_LOG='/data/mc/logs/latest.log'
4
+ ANSI=re.compile('\\x1B(?:[@-Z\\\\-_]|\\[[0-?]*[ -/]*[@-~])')
5
+ _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_SLIVER':(f"{LOG_DIR}/sliver.log",'SLIVER LOGS'),'SHOW_LOGS_NGINX':(f"{LOG_DIR}/nginx.log",'NGINX LOGS'),'SHOW_LOGS_NGINX_ACCESS':('/tmp/access.log','NGINX ACCESS LOGS'),'SHOW_LOGS_NGINX_ERROR':('/tmp/error.log','NGINX ERROR LOGS')}
6
+ def _read_log(path,label,strip_ansi=False):
7
+ try:
8
+ with open(path)as A:B=ANSI.sub('',A.read())if strip_ansi else A.read()
9
+ return f"{label}:\n{B}"
10
+ except Exception as C:return f"Log error: {C}"
11
+ def _read_mc_log():
12
+ try:
13
+ if not os.path.exists(MC_LOG):return'Minecraft latest.log not found yet.'
14
+ with open(MC_LOG)as A:return f"=== Minecraft latest.log ===\n{A.read()}"
15
+ except Exception as B:return f"Log error: {B}"
16
+ def _read_all_logs():
17
+ try:
18
+ A=[]
19
+ for B in sorted(os.listdir(LOG_DIR)):
20
+ if B.endswith('.log'):
21
+ with open(os.path.join(LOG_DIR,B))as C:A.append(f"=== {B} ===\n{C.read()}\n")
22
+ if os.path.exists(MC_LOG):
23
+ with open(MC_LOG)as C:A.append(f"=== Minecraft latest.log ===\n{C.read()}\n")
24
+ return'\n'.join(A)if A else'No logs found.'
25
+ except Exception as D:return f"Log error: {D}"
26
+ def fake_model(text):
27
+ A=text.strip()
28
+ if A=='SHOW_ALL_LOGS':return _read_all_logs()
29
+ if A=='SHOW_LOGS_MC':return _read_mc_log()
30
+ B=_LOG_CMDS.get(A)
31
+ if B:return _read_log(*B)
32
+ return f"Model processed: {text}"
33
+ 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)