misukisu commited on
Commit
6f8fe2b
·
verified ·
1 Parent(s): 6af959d

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +65 -0
app.py ADDED
@@ -0,0 +1,65 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import http.server
2
+ import socketserver
3
+ import os
4
+ import re
5
+
6
+ PORT = 7860
7
+ LOG_FILE = "/bedrock/server_combined.log"
8
+
9
+ HTML_TEMPLATE = """<!DOCTYPE html>
10
+ <html>
11
+ <head>
12
+ <title>Bedrock Server Console</title>
13
+ <meta http-equiv="refresh" content="3">
14
+ <style>
15
+ body { font-family: monospace; background: #121212; color: #e0e0e0; padding: 20px; }
16
+ .box { background: #1e1e1e; padding: 15px; border-radius: 8px; border: 1px solid #333; margin-bottom: 20px; }
17
+ .claim { background: #2e4a2e; color: #a3e635; padding: 10px; border-radius: 5px; font-size: 16px; font-weight: bold; }
18
+ pre { white-space: pre-wrap; word-wrap: break-word; font-size: 13px; color: #d4d4d4; }
19
+ a { color: #38bdf8; text-decoration: underline; }
20
+ </style>
21
+ </head>
22
+ <body>
23
+ <h2>🧱 Hugging Face Bedrock Server</h2>
24
+ <div class="box">
25
+ <h3>🔗 playit.gg Claim URL:</h3>
26
+ <p class="claim">{claim_url}</p>
27
+ </div>
28
+ <div class="box">
29
+ <h3>📜 Live Console Output (auto-refreshes every 3s):</h3>
30
+ <pre>{logs}</pre>
31
+ </div>
32
+ </body>
33
+ </html>
34
+ """
35
+
36
+ class Handler(http.server.SimpleHTTPRequestHandler):
37
+ def do_GET(self):
38
+ logs = "Loading server logs..."
39
+ claim_url = "Waiting for playit.gg to generate claim link..."
40
+
41
+ if os.path.exists(LOG_FILE):
42
+ try:
43
+ with open(LOG_FILE, "r", errors="ignore") as f:
44
+ all_lines = f.readlines()
45
+ logs = "".join(all_lines[-100:])
46
+
47
+ match = re.search(r'(https://playit\.gg/claim/[a-zA-Z0-9]+)', logs)
48
+ if match:
49
+ url = match.group(1)
50
+ claim_url = f'<a href="{url}" target="_blank">{url}</a> (Click to link to your playit account)'
51
+ elif "playit" in logs.lower() and "ready" in logs.lower():
52
+ claim_url = "Tunnel active! Check your playit.gg dashboard for your public Bedrock IP & Port."
53
+ except Exception as e:
54
+ logs = f"Error reading logs: {e}"
55
+
56
+ html = HTML_TEMPLATE.format(claim_url=claim_url, logs=logs)
57
+
58
+ self.send_response(200)
59
+ self.send_header("Content-type", "text/html; charset=utf-8")
60
+ self.end_headers()
61
+ self.wfile.write(html.encode("utf-8"))
62
+
63
+ with socketserver.TCPServer(("", PORT), Handler) as httpd:
64
+ print(f"Web interface running on port {PORT}")
65
+ httpd.serve_forever()