Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
|
@@ -2,7 +2,7 @@ import subprocess
|
|
| 2 |
import sys
|
| 3 |
import os
|
| 4 |
import socket
|
| 5 |
-
from flask import Flask
|
| 6 |
|
| 7 |
# تحديد المسار الحالي
|
| 8 |
BASE_DIR = os.path.dirname(os.path.abspath(__file__))
|
|
@@ -16,8 +16,8 @@ def is_port_in_use(port):
|
|
| 16 |
with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as s:
|
| 17 |
return s.connect_ex(("127.0.0.1", port)) == 0
|
| 18 |
|
| 19 |
-
def find_free_port(start_port=
|
| 20 |
-
"""إيجاد بورت متاح
|
| 21 |
port = start_port
|
| 22 |
while port <= max_port:
|
| 23 |
if not is_port_in_use(port):
|
|
@@ -25,16 +25,25 @@ def find_free_port(start_port=7520, max_port=7600):
|
|
| 25 |
port += 1
|
| 26 |
raise RuntimeError("❌ لم يتم العثور على أي بورت فارغ في النطاق المحدد")
|
| 27 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 28 |
if __name__ == "__main__":
|
| 29 |
try:
|
| 30 |
-
# تشغيل main.py
|
| 31 |
subprocess.run([sys.executable, MAIN_FILE], check=True)
|
| 32 |
except subprocess.CalledProcessError as e:
|
| 33 |
print(f"❌ خطأ أثناء تشغيل main.py: {e}")
|
| 34 |
|
| 35 |
-
#
|
| 36 |
-
|
| 37 |
-
print(f"✅ سي
|
| 38 |
|
| 39 |
-
# تشغيل
|
| 40 |
-
app.run(host="0.0.0.0", port=
|
|
|
|
| 2 |
import sys
|
| 3 |
import os
|
| 4 |
import socket
|
| 5 |
+
from flask import Flask, request, redirect
|
| 6 |
|
| 7 |
# تحديد المسار الحالي
|
| 8 |
BASE_DIR = os.path.dirname(os.path.abspath(__file__))
|
|
|
|
| 16 |
with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as s:
|
| 17 |
return s.connect_ex(("127.0.0.1", port)) == 0
|
| 18 |
|
| 19 |
+
def find_free_port(start_port=7600, max_port=7900):
|
| 20 |
+
"""إيجاد بورت متاح لبروكسي Hugging Face"""
|
| 21 |
port = start_port
|
| 22 |
while port <= max_port:
|
| 23 |
if not is_port_in_use(port):
|
|
|
|
| 25 |
port += 1
|
| 26 |
raise RuntimeError("❌ لم يتم العثور على أي بورت فارغ في النطاق المحدد")
|
| 27 |
|
| 28 |
+
@app.route("/")
|
| 29 |
+
def index():
|
| 30 |
+
return "✅ السيرفر يعمل على استقبال 7520"
|
| 31 |
+
|
| 32 |
+
@app.route("/forward", methods=["GET", "POST"])
|
| 33 |
+
def forward_request():
|
| 34 |
+
"""تحويل الطلب إلى بورت Hugging Face"""
|
| 35 |
+
return redirect(f"http://127.0.0.1:{huggingface_port}", code=307)
|
| 36 |
+
|
| 37 |
if __name__ == "__main__":
|
| 38 |
try:
|
| 39 |
+
# تشغيل main.py
|
| 40 |
subprocess.run([sys.executable, MAIN_FILE], check=True)
|
| 41 |
except subprocess.CalledProcessError as e:
|
| 42 |
print(f"❌ خطأ أثناء تشغيل main.py: {e}")
|
| 43 |
|
| 44 |
+
# تحديد بورت Hugging Face
|
| 45 |
+
huggingface_port = find_free_port(7860, 7900)
|
| 46 |
+
print(f"✅ Hugging Face سيعمل على البورت: {huggingface_port}")
|
| 47 |
|
| 48 |
+
# تشغيل استقبال على 7520
|
| 49 |
+
app.run(host="0.0.0.0", port=7520)
|