Spaces:
Paused
Paused
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,42 +1,57 @@
|
|
| 1 |
import os
|
| 2 |
import subprocess
|
| 3 |
-
import threading
|
| 4 |
-
from http.server import SimpleHTTPRequestHandler, HTTPServer
|
| 5 |
|
|
|
|
| 6 |
html_content = """<!DOCTYPE html>
|
| 7 |
<html>
|
| 8 |
-
<head>
|
| 9 |
-
<
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
.status { color: #27ae60; font-weight: bold; }
|
| 15 |
-
</style>
|
| 16 |
-
</head>
|
| 17 |
-
<body>
|
| 18 |
-
<div class="box">
|
| 19 |
-
<h1>AI Inference System</h1>
|
| 20 |
-
<p>Model: GPT-Transformer-v4</p>
|
| 21 |
-
<p>Status: <span class="status">OPERATIONAL</span></p>
|
| 22 |
-
<p>Latency: 12ms</p>
|
| 23 |
-
</div>
|
| 24 |
-
</body>
|
| 25 |
-
</html>"""
|
| 26 |
|
| 27 |
with open("index.html", "w") as f:
|
| 28 |
f.write(html_content)
|
| 29 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 30 |
xray_config = """
|
| 31 |
{
|
| 32 |
-
"log": {
|
| 33 |
-
"access": "none",
|
| 34 |
-
"error": "none",
|
| 35 |
-
"loglevel": "none"
|
| 36 |
-
},
|
| 37 |
"inbounds": [
|
| 38 |
{
|
| 39 |
-
"port":
|
|
|
|
| 40 |
"protocol": "vless",
|
| 41 |
"settings": {
|
| 42 |
"clients": [
|
|
@@ -45,37 +60,26 @@ xray_config = """
|
|
| 45 |
"level": 0
|
| 46 |
}
|
| 47 |
],
|
| 48 |
-
"decryption": "none"
|
| 49 |
-
"fallbacks": [
|
| 50 |
-
{
|
| 51 |
-
"dest": 3000,
|
| 52 |
-
"xver": 0
|
| 53 |
-
}
|
| 54 |
-
]
|
| 55 |
},
|
| 56 |
"streamSettings": {
|
| 57 |
"network": "ws",
|
| 58 |
"wsSettings": {
|
| 59 |
-
"path": "/"
|
| 60 |
}
|
| 61 |
}
|
| 62 |
}
|
| 63 |
],
|
| 64 |
-
"outbounds": [
|
| 65 |
-
{
|
| 66 |
-
"protocol": "freedom"
|
| 67 |
-
}
|
| 68 |
-
]
|
| 69 |
}
|
| 70 |
"""
|
| 71 |
|
| 72 |
with open("config.json", "w") as f:
|
| 73 |
f.write(xray_config)
|
| 74 |
|
| 75 |
-
|
| 76 |
-
|
| 77 |
-
|
| 78 |
-
|
| 79 |
-
threading.Thread(target=run_server, daemon=True).start()
|
| 80 |
|
| 81 |
-
|
|
|
|
|
|
| 1 |
import os
|
| 2 |
import subprocess
|
|
|
|
|
|
|
| 3 |
|
| 4 |
+
# 1. ساخت سایت الکی (HTML)
|
| 5 |
html_content = """<!DOCTYPE html>
|
| 6 |
<html>
|
| 7 |
+
<head><title>AI Cloud</title>
|
| 8 |
+
<style>body{font-family:sans-serif;text-align:center;padding:50px;background:#f5f5f5;}
|
| 9 |
+
.card{background:white;padding:30px;border-radius:10px;display:inline-block;box-shadow:0 2px 5px rgba(0,0,0,0.1);}
|
| 10 |
+
h1{color:#333;} .ok{color:green;font-weight:bold;}</style></head>
|
| 11 |
+
<body><div class="card"><h1>AI Model Serving</h1>
|
| 12 |
+
<p>Status: <span class="ok">RUNNING</span></p><p>Worker ID: #X99-Alpha</p></div></body></html>"""
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 13 |
|
| 14 |
with open("index.html", "w") as f:
|
| 15 |
f.write(html_content)
|
| 16 |
|
| 17 |
+
# 2. تنظیمات Nginx (پلیس ترافیک)
|
| 18 |
+
# اگر مسیر /vl بود بفرست سمت فیلترشکن (پورت 3000)، در غیر این صورت سایت را نشان بده
|
| 19 |
+
nginx_conf = """
|
| 20 |
+
events { worker_connections 1024; }
|
| 21 |
+
http {
|
| 22 |
+
server {
|
| 23 |
+
listen 7860;
|
| 24 |
+
listen [::]:7860;
|
| 25 |
+
root /app;
|
| 26 |
+
index index.html;
|
| 27 |
+
|
| 28 |
+
location / {
|
| 29 |
+
try_files $uri $uri/ =404;
|
| 30 |
+
}
|
| 31 |
+
|
| 32 |
+
location /vl {
|
| 33 |
+
proxy_redirect off;
|
| 34 |
+
proxy_pass http://127.0.0.1:3000;
|
| 35 |
+
proxy_http_version 1.1;
|
| 36 |
+
proxy_set_header Upgrade $http_upgrade;
|
| 37 |
+
proxy_set_header Connection "upgrade";
|
| 38 |
+
proxy_set_header Host $host;
|
| 39 |
+
}
|
| 40 |
+
}
|
| 41 |
+
}
|
| 42 |
+
"""
|
| 43 |
+
|
| 44 |
+
with open("nginx.conf", "w") as f:
|
| 45 |
+
f.write(nginx_conf)
|
| 46 |
+
|
| 47 |
+
# 3. تنظیمات Xray (فیلترشکن روی پورت 3000 مخفی شده)
|
| 48 |
xray_config = """
|
| 49 |
{
|
| 50 |
+
"log": { "loglevel": "none" },
|
|
|
|
|
|
|
|
|
|
|
|
|
| 51 |
"inbounds": [
|
| 52 |
{
|
| 53 |
+
"port": 3000,
|
| 54 |
+
"listen": "127.0.0.1",
|
| 55 |
"protocol": "vless",
|
| 56 |
"settings": {
|
| 57 |
"clients": [
|
|
|
|
| 60 |
"level": 0
|
| 61 |
}
|
| 62 |
],
|
| 63 |
+
"decryption": "none"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 64 |
},
|
| 65 |
"streamSettings": {
|
| 66 |
"network": "ws",
|
| 67 |
"wsSettings": {
|
| 68 |
+
"path": "/vl"
|
| 69 |
}
|
| 70 |
}
|
| 71 |
}
|
| 72 |
],
|
| 73 |
+
"outbounds": [{ "protocol": "freedom" }]
|
|
|
|
|
|
|
|
|
|
|
|
|
| 74 |
}
|
| 75 |
"""
|
| 76 |
|
| 77 |
with open("config.json", "w") as f:
|
| 78 |
f.write(xray_config)
|
| 79 |
|
| 80 |
+
# 4. اجرای همزمان همه
|
| 81 |
+
print("Starting Xray...")
|
| 82 |
+
subprocess.Popen(["./xray", "-c", "config.json"])
|
|
|
|
|
|
|
| 83 |
|
| 84 |
+
print("Starting Nginx...")
|
| 85 |
+
subprocess.run(["nginx", "-c", "/app/nginx.conf", "-g", "daemon off;"])
|