Spaces:
Running
Running
Upload 61 files
Browse files- DeviceManager.py +81 -0
- auto_offload.py +73 -0
- distributed_executor.py +107 -7
- global_memory.json +0 -0
- history.json +5 -193
- main.py +14 -114
- package-lock.json +0 -0
- package.json +6 -10
- peer_server.py +9 -6
- requirements.txt +7 -45
DeviceManager.py
ADDED
|
@@ -0,0 +1,81 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import subprocess
|
| 2 |
+
import GPUtil
|
| 3 |
+
import psutil
|
| 4 |
+
import logging
|
| 5 |
+
|
| 6 |
+
logging.getLogger().setLevel(logging.CRITICAL) # صامت
|
| 7 |
+
|
| 8 |
+
class DeviceManager:
|
| 9 |
+
def __init__(self):
|
| 10 |
+
self.devices = {
|
| 11 |
+
"GPU": self._detect_gpus(),
|
| 12 |
+
"DSP": self._detect_dsps(),
|
| 13 |
+
"NIC": self._detect_nics(),
|
| 14 |
+
"STORAGE": self._detect_storage(),
|
| 15 |
+
"CAPTURE": self._detect_capture(),
|
| 16 |
+
"ACCELERATOR": self._detect_accelerators()
|
| 17 |
+
}
|
| 18 |
+
|
| 19 |
+
# ────────────── اكتشاف الكروت ──────────────
|
| 20 |
+
def _detect_gpus(self):
|
| 21 |
+
try:
|
| 22 |
+
return GPUtil.getGPUs()
|
| 23 |
+
except:
|
| 24 |
+
return []
|
| 25 |
+
|
| 26 |
+
def _detect_dsps(self):
|
| 27 |
+
try:
|
| 28 |
+
output = subprocess.check_output(["aplay", "-l"], stderr=subprocess.DEVNULL).decode()
|
| 29 |
+
return ["DSP_Audio"] if "card" in output.lower() else []
|
| 30 |
+
except:
|
| 31 |
+
return []
|
| 32 |
+
|
| 33 |
+
def _detect_nics(self):
|
| 34 |
+
try:
|
| 35 |
+
return list(psutil.net_if_addrs().keys())
|
| 36 |
+
except:
|
| 37 |
+
return []
|
| 38 |
+
|
| 39 |
+
def _detect_storage(self):
|
| 40 |
+
try:
|
| 41 |
+
output = subprocess.check_output(["lsblk", "-o", "NAME"], stderr=subprocess.DEVNULL).decode()
|
| 42 |
+
return output.split() if output else []
|
| 43 |
+
except:
|
| 44 |
+
return []
|
| 45 |
+
|
| 46 |
+
def _detect_capture(self):
|
| 47 |
+
try:
|
| 48 |
+
output = subprocess.check_output(["v4l2-ctl", "--list-devices"], stderr=subprocess.DEVNULL).decode()
|
| 49 |
+
return output.split(":")[0::2] if output else []
|
| 50 |
+
except:
|
| 51 |
+
return []
|
| 52 |
+
|
| 53 |
+
def _detect_accelerators(self):
|
| 54 |
+
# افتراض: في المستقبل يمكن إضافة اكتشاف حقيقي لـ FPGA/TPU
|
| 55 |
+
return []
|
| 56 |
+
|
| 57 |
+
# ────────────── فحص الحمل ──────────────
|
| 58 |
+
def get_device_load(self, device_type, index=0):
|
| 59 |
+
try:
|
| 60 |
+
if device_type == "GPU" and self.devices["GPU"]:
|
| 61 |
+
return self.devices["GPU"][index].load * 100
|
| 62 |
+
elif device_type == "DSP" and self.devices["DSP"]:
|
| 63 |
+
return 10 # افتراضي: ما في API للحمل
|
| 64 |
+
elif device_type == "NIC" and self.devices["NIC"]:
|
| 65 |
+
return psutil.net_io_counters().bytes_sent / (1024 * 1024) # مثال بسيط
|
| 66 |
+
elif device_type == "STORAGE" and self.devices["STORAGE"]:
|
| 67 |
+
return psutil.disk_usage('/').percent
|
| 68 |
+
elif device_type == "CAPTURE" and self.devices["CAPTURE"]:
|
| 69 |
+
return 20 # افتراضي: حمل منخفض
|
| 70 |
+
elif device_type == "ACCELERATOR" and self.devices["ACCELERATOR"]:
|
| 71 |
+
return 15 # افتراضي
|
| 72 |
+
return 0
|
| 73 |
+
except:
|
| 74 |
+
return 0
|
| 75 |
+
|
| 76 |
+
# ────────────── منطق 30% / 70% ──────────────
|
| 77 |
+
def can_receive(self, device_type, index=0):
|
| 78 |
+
return self.get_device_load(device_type, index) <= 30
|
| 79 |
+
|
| 80 |
+
def should_offload(self, device_type, index=0):
|
| 81 |
+
return self.get_device_load(device_type, index) >= 70
|
auto_offload.py
ADDED
|
@@ -0,0 +1,73 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import subprocess
|
| 2 |
+
import torch
|
| 3 |
+
import GPUtil
|
| 4 |
+
import psutil
|
| 5 |
+
import logging
|
| 6 |
+
|
| 7 |
+
logging.getLogger().setLevel(logging.CRITICAL) # صامت تمامًا
|
| 8 |
+
|
| 9 |
+
class DeviceManager:
|
| 10 |
+
def __init__(self):
|
| 11 |
+
self.gpus = self._detect_gpus()
|
| 12 |
+
self.dsps = self._detect_dsps()
|
| 13 |
+
# في المستقبل يمكن إضافة كروت أخرى بنفس النمط
|
| 14 |
+
|
| 15 |
+
def _detect_gpus(self):
|
| 16 |
+
"""اكتشاف جميع الـ GPUs المتاحة"""
|
| 17 |
+
try:
|
| 18 |
+
return GPUtil.getGPUs()
|
| 19 |
+
except Exception:
|
| 20 |
+
return []
|
| 21 |
+
|
| 22 |
+
def _detect_dsps(self):
|
| 23 |
+
"""تحقق من وجود DSP أو كروت صوتية"""
|
| 24 |
+
try:
|
| 25 |
+
output = subprocess.check_output(["aplay", "-l"], stderr=subprocess.DEVNULL).decode()
|
| 26 |
+
if "card" in output.lower():
|
| 27 |
+
return ["DSP_Audio"]
|
| 28 |
+
return []
|
| 29 |
+
except Exception:
|
| 30 |
+
return []
|
| 31 |
+
|
| 32 |
+
def get_device_load(self, device_type, index=0):
|
| 33 |
+
"""إرجاع نسبة الحمل للجهاز"""
|
| 34 |
+
if device_type == "GPU" and self.gpus:
|
| 35 |
+
try:
|
| 36 |
+
return self.gpus[index].load * 100 # نسبة مئوية
|
| 37 |
+
except Exception:
|
| 38 |
+
return 0
|
| 39 |
+
elif device_type == "DSP" and self.dsps:
|
| 40 |
+
# هنا ما في API رسمية، نفترض DSP قليل الحمل دائمًا كمثال
|
| 41 |
+
return 10
|
| 42 |
+
return 0
|
| 43 |
+
|
| 44 |
+
class AutoOffloadExecutor:
|
| 45 |
+
def __init__(self, executor):
|
| 46 |
+
self.executor = executor
|
| 47 |
+
self.devices = DeviceManager()
|
| 48 |
+
|
| 49 |
+
def _should_offload(self, device_type, index=0):
|
| 50 |
+
load = self.devices.get_device_load(device_type, index)
|
| 51 |
+
return load >= 70
|
| 52 |
+
|
| 53 |
+
def _can_receive(self, device_type, index=0):
|
| 54 |
+
load = self.devices.get_device_load(device_type, index)
|
| 55 |
+
return load <= 30
|
| 56 |
+
|
| 57 |
+
def submit_auto(self, task_func, *args, task_type=None, **kwargs):
|
| 58 |
+
"""إرسال تلقائي حسب حالة الكروت"""
|
| 59 |
+
device_type = "CPU" # افتراضي
|
| 60 |
+
if task_type == "video" and self.devices.gpus:
|
| 61 |
+
device_type = "GPU"
|
| 62 |
+
elif task_type == "audio" and self.devices.dsps:
|
| 63 |
+
device_type = "DSP"
|
| 64 |
+
|
| 65 |
+
if self._should_offload(device_type):
|
| 66 |
+
# حمل عالي → أرسل
|
| 67 |
+
self.executor.submit(task_func, *args, **kwargs)
|
| 68 |
+
elif self._can_receive(device_type):
|
| 69 |
+
# حمل منخفض → نفذ محليًا
|
| 70 |
+
task_func(*args, **kwargs)
|
| 71 |
+
else:
|
| 72 |
+
# حمل متوسط → نفذ محليًا
|
| 73 |
+
task_func(*args, **kwargs)
|
distributed_executor.py
CHANGED
|
@@ -1,15 +1,95 @@
|
|
| 1 |
import threading
|
| 2 |
import queue
|
| 3 |
import time
|
| 4 |
-
import json
|
| 5 |
from typing import Callable, Dict, List
|
| 6 |
import socket
|
| 7 |
from zeroconf import Zeroconf, ServiceBrowser, ServiceInfo
|
| 8 |
import logging
|
| 9 |
import requests
|
|
|
|
|
|
|
|
|
|
|
|
|
| 10 |
|
| 11 |
logging.basicConfig(level=logging.INFO)
|
| 12 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 13 |
class PeerRegistry:
|
| 14 |
def __init__(self):
|
| 15 |
self._peers = {}
|
|
@@ -60,7 +140,7 @@ class PeerRegistry:
|
|
| 60 |
self.add_service(zc, type_, name)
|
| 61 |
|
| 62 |
def remove_service(self, zc, type_, name):
|
| 63 |
-
pass
|
| 64 |
|
| 65 |
listener = Listener()
|
| 66 |
ServiceBrowser(self._zeroconf, "_tasknode._tcp.local.", listener)
|
|
@@ -78,7 +158,7 @@ class PeerRegistry:
|
|
| 78 |
s.close()
|
| 79 |
return ip
|
| 80 |
|
| 81 |
-
|
| 82 |
class DistributedExecutor:
|
| 83 |
def __init__(self, shared_secret: str):
|
| 84 |
self.peer_registry = PeerRegistry()
|
|
@@ -86,6 +166,7 @@ class DistributedExecutor:
|
|
| 86 |
self.task_queue = queue.PriorityQueue()
|
| 87 |
self.result_cache = {}
|
| 88 |
self.available_peers = []
|
|
|
|
| 89 |
self._init_peer_discovery()
|
| 90 |
|
| 91 |
def _init_peer_discovery(self):
|
|
@@ -97,7 +178,26 @@ class DistributedExecutor:
|
|
| 97 |
|
| 98 |
threading.Thread(target=discovery_loop, daemon=True).start()
|
| 99 |
|
| 100 |
-
def submit(self, task_func: Callable, *args, **kwargs):
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 101 |
task_id = f"{task_func.__name__}_{time.time()}"
|
| 102 |
|
| 103 |
task = {
|
|
@@ -122,6 +222,7 @@ class DistributedExecutor:
|
|
| 122 |
self._send_to_peer(peer, task)
|
| 123 |
else:
|
| 124 |
logging.warning("⚠️ لا توجد أجهزة متاحة - سيتم تنفيذ المهمة محلياً")
|
|
|
|
| 125 |
|
| 126 |
def _is_local_ip(self, ip: str) -> bool:
|
| 127 |
return (
|
|
@@ -142,7 +243,7 @@ class DistributedExecutor:
|
|
| 142 |
logging.error(f"❌ فشل إرسال المهمة لـ {peer['node_id']}: {e}")
|
| 143 |
return None
|
| 144 |
|
| 145 |
-
|
| 146 |
if __name__ == "__main__":
|
| 147 |
executor = DistributedExecutor("my_secret_key")
|
| 148 |
executor.peer_registry.register_service("node1", 7520, load=0.1)
|
|
@@ -151,5 +252,4 @@ if __name__ == "__main__":
|
|
| 151 |
def example_task(x):
|
| 152 |
return x * x
|
| 153 |
|
| 154 |
-
executor.submit(example_task, 5)
|
| 155 |
-
|
|
|
|
| 1 |
import threading
|
| 2 |
import queue
|
| 3 |
import time
|
|
|
|
| 4 |
from typing import Callable, Dict, List
|
| 5 |
import socket
|
| 6 |
from zeroconf import Zeroconf, ServiceBrowser, ServiceInfo
|
| 7 |
import logging
|
| 8 |
import requests
|
| 9 |
+
import subprocess
|
| 10 |
+
import psutil
|
| 11 |
+
import GPUtil
|
| 12 |
+
from processor_manager import ResourceMonitor
|
| 13 |
|
| 14 |
logging.basicConfig(level=logging.INFO)
|
| 15 |
|
| 16 |
+
# ─────────────── Device Manager عام ───────────────
|
| 17 |
+
class DeviceManager:
|
| 18 |
+
def __init__(self):
|
| 19 |
+
self.devices = {
|
| 20 |
+
"GPU": self._detect_gpus(),
|
| 21 |
+
"DSP": self._detect_dsps(),
|
| 22 |
+
"NIC": self._detect_nics(),
|
| 23 |
+
"STORAGE": self._detect_storage(),
|
| 24 |
+
"CAPTURE": self._detect_capture(),
|
| 25 |
+
"ACCELERATOR": self._detect_accelerators()
|
| 26 |
+
}
|
| 27 |
+
|
| 28 |
+
# اكتشاف الأجهزة
|
| 29 |
+
def _detect_gpus(self):
|
| 30 |
+
try:
|
| 31 |
+
return GPUtil.getGPUs()
|
| 32 |
+
except:
|
| 33 |
+
return []
|
| 34 |
+
|
| 35 |
+
def _detect_dsps(self):
|
| 36 |
+
try:
|
| 37 |
+
output = subprocess.check_output(["aplay", "-l"], stderr=subprocess.DEVNULL).decode()
|
| 38 |
+
return ["DSP_Audio"] if "card" in output.lower() else []
|
| 39 |
+
except:
|
| 40 |
+
return []
|
| 41 |
+
|
| 42 |
+
def _detect_nics(self):
|
| 43 |
+
try:
|
| 44 |
+
return list(psutil.net_if_addrs().keys())
|
| 45 |
+
except:
|
| 46 |
+
return []
|
| 47 |
+
|
| 48 |
+
def _detect_storage(self):
|
| 49 |
+
try:
|
| 50 |
+
output = subprocess.check_output(["lsblk", "-o", "NAME"], stderr=subprocess.DEVNULL).decode()
|
| 51 |
+
return output.split() if output else []
|
| 52 |
+
except:
|
| 53 |
+
return []
|
| 54 |
+
|
| 55 |
+
def _detect_capture(self):
|
| 56 |
+
try:
|
| 57 |
+
output = subprocess.check_output(["v4l2-ctl", "--list-devices"], stderr=subprocess.DEVNULL).decode()
|
| 58 |
+
return output.split(":")[0::2] if output else []
|
| 59 |
+
except:
|
| 60 |
+
return []
|
| 61 |
+
|
| 62 |
+
def _detect_accelerators(self):
|
| 63 |
+
# افتراضي: يمكن إضافة اكتشاف حقيقي مستقبلاً
|
| 64 |
+
return ["Accelerator_Device"]
|
| 65 |
+
|
| 66 |
+
# قياس الحمل
|
| 67 |
+
def get_device_load(self, device_type, index=0):
|
| 68 |
+
try:
|
| 69 |
+
if device_type == "GPU" and self.devices["GPU"]:
|
| 70 |
+
return self.devices["GPU"][index].load * 100
|
| 71 |
+
elif device_type == "DSP" and self.devices["DSP"]:
|
| 72 |
+
return 10 # افتراضي
|
| 73 |
+
elif device_type == "NIC" and self.devices["NIC"]:
|
| 74 |
+
return psutil.net_io_counters().bytes_sent / (1024 * 1024) # MB sent كمثال
|
| 75 |
+
elif device_type == "STORAGE" and self.devices["STORAGE"]:
|
| 76 |
+
return psutil.disk_usage('/').percent
|
| 77 |
+
elif device_type == "CAPTURE" and self.devices["CAPTURE"]:
|
| 78 |
+
return 20 # افتراضي
|
| 79 |
+
elif device_type == "ACCELERATOR" and self.devices["ACCELERATOR"]:
|
| 80 |
+
return 15 # افتراضي
|
| 81 |
+
return 0
|
| 82 |
+
except:
|
| 83 |
+
return 0
|
| 84 |
+
|
| 85 |
+
# منطق الاستقبال/الإرسال
|
| 86 |
+
def can_receive(self, device_type, index=0):
|
| 87 |
+
return self.get_device_load(device_type, index) <= 30
|
| 88 |
+
|
| 89 |
+
def should_offload(self, device_type, index=0):
|
| 90 |
+
return self.get_device_load(device_type, index) >= 70
|
| 91 |
+
|
| 92 |
+
# ─────────────── Peer Registry ───────────────
|
| 93 |
class PeerRegistry:
|
| 94 |
def __init__(self):
|
| 95 |
self._peers = {}
|
|
|
|
| 140 |
self.add_service(zc, type_, name)
|
| 141 |
|
| 142 |
def remove_service(self, zc, type_, name):
|
| 143 |
+
pass
|
| 144 |
|
| 145 |
listener = Listener()
|
| 146 |
ServiceBrowser(self._zeroconf, "_tasknode._tcp.local.", listener)
|
|
|
|
| 158 |
s.close()
|
| 159 |
return ip
|
| 160 |
|
| 161 |
+
# ─────────────── Distributed Executor ───────────────
|
| 162 |
class DistributedExecutor:
|
| 163 |
def __init__(self, shared_secret: str):
|
| 164 |
self.peer_registry = PeerRegistry()
|
|
|
|
| 166 |
self.task_queue = queue.PriorityQueue()
|
| 167 |
self.result_cache = {}
|
| 168 |
self.available_peers = []
|
| 169 |
+
self.devices = DeviceManager()
|
| 170 |
self._init_peer_discovery()
|
| 171 |
|
| 172 |
def _init_peer_discovery(self):
|
|
|
|
| 178 |
|
| 179 |
threading.Thread(target=discovery_loop, daemon=True).start()
|
| 180 |
|
| 181 |
+
def submit(self, task_func: Callable, *args, task_type=None, **kwargs):
|
| 182 |
+
monitor = ResourceMonitor().current_load()
|
| 183 |
+
avg_cpu = monitor["average"]["cpu"]
|
| 184 |
+
avg_mem = monitor["average"]["mem_percent"] if "mem_percent" in monitor["average"] else 0
|
| 185 |
+
|
| 186 |
+
# تحديد نوع الجهاز
|
| 187 |
+
device_type = task_type.upper() if task_type else "CPU"
|
| 188 |
+
|
| 189 |
+
# فحص الحمل
|
| 190 |
+
if (avg_cpu > 0.6 or avg_mem > 85 or self.devices.should_offload(device_type)):
|
| 191 |
+
logging.info(f"⚠️ الح��ل مرتفع على {device_type} - إرسال المهمة للأقران")
|
| 192 |
+
self._offload_task(task_func, *args, **kwargs)
|
| 193 |
+
elif (avg_cpu <= 0.3 and self.devices.can_receive(device_type)):
|
| 194 |
+
logging.info(f"✅ الحمل منخفض على {device_type} - تنفيذ المهمة محلياً")
|
| 195 |
+
return task_func(*args, **kwargs)
|
| 196 |
+
else:
|
| 197 |
+
logging.info(f"ℹ️ الحمل متوسط على {device_type} - تنفيذ المهمة محلياً")
|
| 198 |
+
return task_func(*args, **kwargs)
|
| 199 |
+
|
| 200 |
+
def _offload_task(self, task_func: Callable, *args, **kwargs):
|
| 201 |
task_id = f"{task_func.__name__}_{time.time()}"
|
| 202 |
|
| 203 |
task = {
|
|
|
|
| 222 |
self._send_to_peer(peer, task)
|
| 223 |
else:
|
| 224 |
logging.warning("⚠️ لا توجد أجهزة متاحة - سيتم تنفيذ المهمة محلياً")
|
| 225 |
+
task_func(*args, **kwargs)
|
| 226 |
|
| 227 |
def _is_local_ip(self, ip: str) -> bool:
|
| 228 |
return (
|
|
|
|
| 243 |
logging.error(f"❌ فشل إرسال المهمة لـ {peer['node_id']}: {e}")
|
| 244 |
return None
|
| 245 |
|
| 246 |
+
# ─────────────── تشغيل رئيسي ───────────────
|
| 247 |
if __name__ == "__main__":
|
| 248 |
executor = DistributedExecutor("my_secret_key")
|
| 249 |
executor.peer_registry.register_service("node1", 7520, load=0.1)
|
|
|
|
| 252 |
def example_task(x):
|
| 253 |
return x * x
|
| 254 |
|
| 255 |
+
executor.submit(example_task, 5, task_type="GPU")
|
|
|
global_memory.json
CHANGED
|
The diff for this file is too large to render.
See raw diff
|
|
|
history.json
CHANGED
|
@@ -1,214 +1,26 @@
|
|
| 1 |
[
|
| 2 |
{
|
| 3 |
"role": "user",
|
| 4 |
-
"content": "
|
| 5 |
},
|
| 6 |
{
|
| 7 |
"role": "assistant",
|
| 8 |
-
"content": "
|
| 9 |
-
},
|
| 10 |
-
{
|
| 11 |
-
"role": "user",
|
| 12 |
-
"content": "كيف حالك"
|
| 13 |
-
},
|
| 14 |
-
{
|
| 15 |
-
"role": "assistant",
|
| 16 |
-
"content": "لم أستطع الحصول على استجابة من الواجهة بعد عدة محاولات. آخر خطأ: Error code: 401 - {'error': {'message': 'Incorrect API key provided: sk-proj-********************************************************************************************************************************************************WYkA. You can find your API key at https://platform.openai.com/account/api-keys.', 'type': 'invalid_request_error', 'param': None, 'code': 'invalid_api_key'}}"
|
| 17 |
-
},
|
| 18 |
-
{
|
| 19 |
-
"role": "user",
|
| 20 |
-
"content": "كيف حالك"
|
| 21 |
-
},
|
| 22 |
-
{
|
| 23 |
-
"role": "assistant",
|
| 24 |
-
"content": "لم أستطع الحصول على استجابة من الواجهة بعد عدة محاولات. آخر خطأ: Error code: 401 - {'error': {'message': 'Incorrect API key provided: sk-proj-********************************************************************************************************************************************************WYkA. You can find your API key at https://platform.openai.com/account/api-keys.', 'type': 'invalid_request_error', 'param': None, 'code': 'invalid_api_key'}}"
|
| 25 |
-
},
|
| 26 |
-
{
|
| 27 |
-
"role": "user",
|
| 28 |
-
"content": "كيف حالك\u001b[2~"
|
| 29 |
-
},
|
| 30 |
-
{
|
| 31 |
-
"role": "assistant",
|
| 32 |
-
"content": "لم أستطع الحصول على استجابة من الواجهة بعد عدة محاولات. آخر خطأ: Error code: 401 - {'error': {'message': 'Incorrect API key provided: sk-proj-********************************************************************************************************************************************************WYkA. You can find your API key at https://platform.openai.com/account/api-keys.', 'type': 'invalid_request_error', 'param': None, 'code': 'invalid_api_key'}}"
|
| 33 |
-
},
|
| 34 |
-
{
|
| 35 |
-
"role": "user",
|
| 36 |
-
"content": "كيف حالك"
|
| 37 |
-
},
|
| 38 |
-
{
|
| 39 |
-
"role": "assistant",
|
| 40 |
-
"content": "لم أستطع الحصول على استجابة من الواجهة بعد عدة محاولات. آخر خطأ: Error code: 401 - {'error': {'message': 'Incorrect API key provided: sk-proj-********************************************************************************************************************************************************WYkA. You can find your API key at https://platform.openai.com/account/api-keys.', 'type': 'invalid_request_error', 'param': None, 'code': 'invalid_api_key'}}"
|
| 41 |
-
},
|
| 42 |
-
{
|
| 43 |
-
"role": "user",
|
| 44 |
-
"content": "hi"
|
| 45 |
-
},
|
| 46 |
-
{
|
| 47 |
-
"role": "assistant",
|
| 48 |
-
"content": "لم أستطع الحصول على استجابة من الواجهة بعد عدة محاولات. آخر خطأ: Error code: 401 - {'error': {'message': 'Incorrect API key provided: sk-proj-********************************************************************************************************************************************************WYkA. You can find your API key at https://platform.openai.com/account/api-keys.', 'type': 'invalid_request_error', 'param': None, 'code': 'invalid_api_key'}}"
|
| 49 |
-
},
|
| 50 |
-
{
|
| 51 |
-
"role": "user",
|
| 52 |
-
"content": "كيف حالك؟"
|
| 53 |
-
},
|
| 54 |
-
{
|
| 55 |
-
"role": "assistant",
|
| 56 |
-
"content": "لم أستطع الحصول على استجابة من الواجهة بعد عدة محاولات. آخر خطأ: Error code: 401 - {'error': {'message': 'Incorrect API key provided: sk-proj-********************************************************************************************************************************************************WYkA. You can find your API key at https://platform.openai.com/account/api-keys.', 'type': 'invalid_request_error', 'param': None, 'code': 'invalid_api_key'}}"
|
| 57 |
-
},
|
| 58 |
-
{
|
| 59 |
-
"role": "user",
|
| 60 |
-
"content": "كيف حالك"
|
| 61 |
-
},
|
| 62 |
-
{
|
| 63 |
-
"role": "assistant",
|
| 64 |
-
"content": "لم أستطع الحصول على استجابة من الواجهة بعد عدة محاولات. آخر خطأ: Error code: 401 - {'error': {'message': 'Incorrect API key provided: sk-proj-********************************************************************************************************************************************************WYkA. You can find your API key at https://platform.openai.com/account/api-keys.', 'type': 'invalid_request_error', 'param': None, 'code': 'invalid_api_key'}}"
|
| 65 |
-
},
|
| 66 |
-
{
|
| 67 |
-
"role": "user",
|
| 68 |
-
"content": ";d"
|
| 69 |
-
},
|
| 70 |
-
{
|
| 71 |
-
"role": "assistant",
|
| 72 |
-
"content": "لم أستطع الحصول على استجابة من الواجهة بعد عدة محاولات. آخر خطأ: Error code: 401 - {'error': {'message': 'Incorrect API key provided: sk-proj-********************************************************************************************************************************************************WYkA. You can find your API key at https://platform.openai.com/account/api-keys.', 'type': 'invalid_request_error', 'param': None, 'code': 'invalid_api_key'}}"
|
| 73 |
-
},
|
| 74 |
-
{
|
| 75 |
-
"role": "user",
|
| 76 |
-
"content": "curl -fsSL https://ollama.com/install.sh | sh"
|
| 77 |
-
},
|
| 78 |
-
{
|
| 79 |
-
"role": "assistant",
|
| 80 |
-
"content": "لم أستطع الحصول على استجابة من الواجهة بعد عدة محاولات. آخر خطأ: Error code: 401 - {'error': {'message': 'Incorrect API key provided: sk-proj-********************************************************************************************************************************************************WYkA. You can find your API key at https://platform.openai.com/account/api-keys.', 'type': 'invalid_request_error', 'param': None, 'code': 'invalid_api_key'}}"
|
| 81 |
-
},
|
| 82 |
-
{
|
| 83 |
-
"role": "user",
|
| 84 |
-
"content": "ollama run mistral"
|
| 85 |
-
},
|
| 86 |
-
{
|
| 87 |
-
"role": "assistant",
|
| 88 |
-
"content": "لم أستطع الحصول على استجابة من الواجهة بعد عدة محاولات. آخر خطأ: Error code: 401 - {'error': {'message': 'Incorrect API key provided: sk-proj-********************************************************************************************************************************************************WYkA. You can find your API key at https://platform.openai.com/account/api-keys.', 'type': 'invalid_request_error', 'param': None, 'code': 'invalid_api_key'}}"
|
| 89 |
-
},
|
| 90 |
-
{
|
| 91 |
-
"role": "user",
|
| 92 |
-
"content": "hi"
|
| 93 |
-
},
|
| 94 |
-
{
|
| 95 |
-
"role": "user",
|
| 96 |
-
"content": "hi"
|
| 97 |
-
},
|
| 98 |
-
{
|
| 99 |
-
"role": "assistant",
|
| 100 |
-
"content": "لم أستطع الحصول على استجابة من Ollama بعد عدة محاولات. آخر خطأ: HTTPConnectionPool(host='127.0.0.1', port=11434): Read timed out. (read timeout=120)"
|
| 101 |
-
},
|
| 102 |
-
{
|
| 103 |
-
"role": "user",
|
| 104 |
-
"content": "مرحبا"
|
| 105 |
-
},
|
| 106 |
-
{
|
| 107 |
-
"role": "assistant",
|
| 108 |
-
"content": "لم أستطع الحصول على استجابة من Ollama بعد عدة محاولات. آخر خطأ: HTTPConnectionPool(host='127.0.0.1', port=2570): Max retries exceeded with url: /api/chat (Caused by NewConnectionError('<urllib3.connection.HTTPConnection object at 0x735844024860>: Failed to establish a new connection: [Errno 111] Connection refused'))"
|
| 109 |
-
},
|
| 110 |
-
{
|
| 111 |
-
"role": "assistant",
|
| 112 |
-
"content": "نتيجة تشغيل السكربت 'ai_controller.py':\n(لا يوجد أي مخرجات)"
|
| 113 |
-
},
|
| 114 |
-
{
|
| 115 |
-
"role": "assistant",
|
| 116 |
-
"content": "نتيجة تشغيل السكربت 'nora_mother_ai.py':\n[STDOUT]\n[!] لا يوجد فقرات <p> في الصفحة."
|
| 117 |
-
},
|
| 118 |
-
{
|
| 119 |
-
"role": "assistant",
|
| 120 |
-
"content": "نتيجة تشغيل السكربت 'server_scan.py':\n(لا يوجد أي مخرجات)"
|
| 121 |
-
},
|
| 122 |
-
{
|
| 123 |
-
"role": "assistant",
|
| 124 |
-
"content": "نتيجة تشغيل السكربت 'self_learning.py':\n(لا يوجد أي مخرجات)"
|
| 125 |
-
},
|
| 126 |
-
{
|
| 127 |
-
"role": "assistant",
|
| 128 |
-
"content": "نتيجة تشغيل السكربت 'run_model.py':\nخرج السكربت بكود 1.\n[STDERR]\ngguf_init_from_file_impl: failed to read magic\nllama_model_load: error loading model: llama_model_loader: failed to load model from /home/osama/nouraai/Mistral-7B-Instruct-v0.1\n\nllama_model_load_from_file_impl: failed to load model\nTraceback (most recent call last):\n File \"/home/osama/nouraai/run_model.py\", line 3, in <module>\n llm = Llama(\n ^^^^^^\n File \"/home/osama/.local/lib/python3.12/site-packages/llama_cpp/llama.py\", line 372, in __init__\n internals.LlamaModel(\n File \"/home/osama/.local/lib/python3.12/site-packages/llama_cpp/_internals.py\", line 56, in __init__\n raise ValueError(f\"Failed to load model from file: {path_model}\")\nValueError: Failed to load model from file: /home/osama/nouraai/Mistral-7B-Instruct-v0.1"
|
| 129 |
-
},
|
| 130 |
-
{
|
| 131 |
-
"role": "assistant",
|
| 132 |
-
"content": "نتيجة تشغيل السكربت 'facebook_bot.py':\nخرج السكربت بكود 1.\n[STDERR]\nTraceback (most recent call last):\n File \"/home/osama/nouraai/facebook_bot.py\", line 64, in <module>\n asyncio.run(post_to_facebook(email, password, message, image_path))\n File \"/usr/lib/python3.12/asyncio/runners.py\", line 194, in run\n return runner.run(main)\n ^^^^^^^^^^^^^^^^\n File \"/usr/lib/python3.12/asyncio/runners.py\", line 118, in run\n return self._loop.run_until_complete(task)\n ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n File \"/usr/lib/python3.12/asyncio/base_events.py\", line 687, in run_until_complete\n return future.result()\n ^^^^^^^^^^^^^^^\n File \"/home/osama/nouraai/facebook_bot.py\", line 7, in post_to_facebook\n browser = await p.chromium.launch(headless=False) # headless=True إذا تريد بدون واجهة\n ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n File \"/usr/local/lib/python3.12/dist-packages/playwright/async_api/_generated.py\", line 14438, in launch\n await self._impl_obj.launch(\n File \"/usr/local/lib/python3.12/dist-packages/playwright/_impl/_browser_type.py\", line 98, in launch\n await self._channel.send(\n File \"/usr/local/lib/python3.12/dist-packages/playwright/_impl/_connection.py\", line 69, in send\n return await self._connection.wrap_api_call(\n ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n File \"/usr/local/lib/python3.12/dist-packages/playwright/_impl/_connection.py\", line 558, in wrap_api_call\n raise rewrite_error(error, f\"{parsed_st['apiName']}: {error}\") from None\nplaywright._impl._errors.Error: BrowserType.launch: Executable doesn't exist at /home/osama/.cache/ms-playwright/chromium-1179/chrome-linux/chrome\n╔════════════════════════════════════════════════════════════╗\n║ Looks like Playwright was just installed or updated. ║\n║ Please run the following command to download new browsers: ║\n║ ║\n║ playwright install ║\n║ ║\n║ <3 Playwright Team ║\n╚════════════════════════════════════════════════════════════╝"
|
| 133 |
-
},
|
| 134 |
-
{
|
| 135 |
-
"role": "user",
|
| 136 |
-
"content": "jj"
|
| 137 |
-
},
|
| 138 |
-
{
|
| 139 |
-
"role": "assistant",
|
| 140 |
-
"content": "لم أستطع الحصول على استجابة من Ollama بعد عدة محاولات. آخر خطأ: HTTPConnectionPool(host='127.0.0.1', port=11434): Max retries exceeded with url: /api/chat (Caused by NewConnectionError('<urllib3.connection.HTTPConnection object at 0x000001E3336690F0>: Failed to establish a new connection: [WinError 10061] No connection could be made because the target machine actively refused it'))"
|
| 141 |
-
},
|
| 142 |
-
{
|
| 143 |
-
"role": "user",
|
| 144 |
-
"content": "مرحبا نورا\r\n"
|
| 145 |
-
},
|
| 146 |
-
{
|
| 147 |
-
"role": "user",
|
| 148 |
-
"content": "مرحبا نورا\r\n"
|
| 149 |
-
},
|
| 150 |
-
{
|
| 151 |
-
"role": "user",
|
| 152 |
-
"content": "مرحبا\r\n"
|
| 153 |
-
},
|
| 154 |
-
{
|
| 155 |
-
"role": "assistant",
|
| 156 |
-
"content": "فشل: 500 - {\"error\":\"unexpected server status: llm server loading model\"}"
|
| 157 |
-
},
|
| 158 |
-
{
|
| 159 |
-
"role": "assistant",
|
| 160 |
-
"content": "فشل: 500 - {\"error\":\"unexpected server status: llm server loading model\"}"
|
| 161 |
-
},
|
| 162 |
-
{
|
| 163 |
-
"role": "user",
|
| 164 |
-
"content": "مرحبا"
|
| 165 |
-
},
|
| 166 |
-
{
|
| 167 |
-
"role": "assistant",
|
| 168 |
-
"content": "فشل: 500 - {\"error\":\"unexpected server status: llm server loading model\"}"
|
| 169 |
-
},
|
| 170 |
-
{
|
| 171 |
-
"role": "assistant",
|
| 172 |
-
"content": "فشل بعد محاولات متعددة. آخر خطأ: Cannot connect to host 127.0.0.1:11434 ssl:default [The remote computer refused the network connection]"
|
| 173 |
-
},
|
| 174 |
-
{
|
| 175 |
-
"role": "user",
|
| 176 |
-
"content": "مرحبا"
|
| 177 |
-
},
|
| 178 |
-
{
|
| 179 |
-
"role": "assistant",
|
| 180 |
-
"content": "فشل بعد محاولات متعددة. آخر خطأ: "
|
| 181 |
},
|
| 182 |
{
|
| 183 |
"role": "user",
|
| 184 |
"content": "مرحبا"
|
| 185 |
},
|
| 186 |
-
{
|
| 187 |
-
"role": "user",
|
| 188 |
-
"content": "مرحبا"
|
| 189 |
-
},
|
| 190 |
-
{
|
| 191 |
-
"role": "assistant",
|
| 192 |
-
"content": "فشل: 500 - {\"error\":\"unexpected server status: llm server loading model\"}"
|
| 193 |
-
},
|
| 194 |
{
|
| 195 |
"role": "assistant",
|
| 196 |
-
"content": "
|
| 197 |
},
|
| 198 |
{
|
| 199 |
"role": "user",
|
| 200 |
-
"content": "
|
| 201 |
-
},
|
| 202 |
-
{
|
| 203 |
-
"role": "assistant",
|
| 204 |
-
"content": "فشل: 500 - {\"error\":\"unexpected server status: llm server loading model\"}\n\nفشل بعد محاولات متعددة. آخر خطأ: Cannot connect to host 127.0.0.1:11434 ssl:default [The remote computer refused the network connection]"
|
| 205 |
-
},
|
| 206 |
-
{
|
| 207 |
-
"role": "user",
|
| 208 |
-
"content": "مرحبا"
|
| 209 |
},
|
| 210 |
{
|
| 211 |
"role": "assistant",
|
| 212 |
-
"content": "
|
| 213 |
}
|
| 214 |
]
|
|
|
|
| 1 |
[
|
| 2 |
{
|
| 3 |
"role": "user",
|
| 4 |
+
"content": "اه"
|
| 5 |
},
|
| 6 |
{
|
| 7 |
"role": "assistant",
|
| 8 |
+
"content": "عذراً، حدث خطأ: 401"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 9 |
},
|
| 10 |
{
|
| 11 |
"role": "user",
|
| 12 |
"content": "مرحبا"
|
| 13 |
},
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 14 |
{
|
| 15 |
"role": "assistant",
|
| 16 |
+
"content": "عذراً، حدث خطأ: 401"
|
| 17 |
},
|
| 18 |
{
|
| 19 |
"role": "user",
|
| 20 |
+
"content": "مم"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 21 |
},
|
| 22 |
{
|
| 23 |
"role": "assistant",
|
| 24 |
+
"content": "عذراً، حدث خطأ: 401"
|
| 25 |
}
|
| 26 |
]
|
main.py
CHANGED
|
@@ -17,6 +17,20 @@ from typing import Any
|
|
| 17 |
|
| 18 |
from flask import Flask, request, jsonify
|
| 19 |
from flask_cors import CORS
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 20 |
|
| 21 |
# ───────────────────── ضبط المسارات ──────────────────────
|
| 22 |
FILE = Path(__file__).resolve()
|
|
@@ -258,117 +272,3 @@ if __name__ == "__main__":
|
|
| 258 |
|
| 259 |
# CLI / إحصائية
|
| 260 |
main()
|
| 261 |
-
import os
|
| 262 |
-
import json
|
| 263 |
-
import torch
|
| 264 |
-
import subprocess
|
| 265 |
-
from transformers import AutoTokenizer, AutoModelForCausalLM
|
| 266 |
-
from responses import generate_reply
|
| 267 |
-
|
| 268 |
-
# إعداد نموذج TinyLlama
|
| 269 |
-
tokenizer = AutoTokenizer.from_pretrained("TinyLlama/TinyLlama-1.1B-Chat-v1.0")
|
| 270 |
-
model = AutoModelForCausalLM.from_pretrained(
|
| 271 |
-
"TinyLlama/TinyLlama-1.1B-Chat-v1.0",
|
| 272 |
-
torch_dtype=torch.float16,
|
| 273 |
-
device_map="auto"
|
| 274 |
-
)
|
| 275 |
-
|
| 276 |
-
# تحميل سجل المحادثة
|
| 277 |
-
history_path = "history.json"
|
| 278 |
-
|
| 279 |
-
if os.path.exists(history_path):
|
| 280 |
-
with open(history_path, "r", encoding="utf-8") as f:
|
| 281 |
-
chat_history = json.load(f)
|
| 282 |
-
else:
|
| 283 |
-
chat_history = []
|
| 284 |
-
|
| 285 |
-
# تنسيق المحادثة للنموذج
|
| 286 |
-
def format_chat(history):
|
| 287 |
-
messages = [
|
| 288 |
-
{"role": "system", "content": "أنت المساعدة نورا. تحدثي بلغة عربية فصحى بسيطة."}
|
| 289 |
-
]
|
| 290 |
-
messages.extend(history)
|
| 291 |
-
return tokenizer.apply_chat_template(messages, tokenize=False, add_generation_prompt=True)
|
| 292 |
-
|
| 293 |
-
# توليد الرد باستخدام TinyLlama
|
| 294 |
-
def generate_llama_response(prompt, max_new_tokens=500):
|
| 295 |
-
inputs = tokenizer(prompt, return_tensors="pt").to(model.device)
|
| 296 |
-
outputs = model.generate(
|
| 297 |
-
**inputs,
|
| 298 |
-
max_new_tokens=max_new_tokens,
|
| 299 |
-
temperature=0.7,
|
| 300 |
-
do_sample=True
|
| 301 |
-
)
|
| 302 |
-
return tokenizer.decode(outputs[0], skip_special_tokens=True)
|
| 303 |
-
|
| 304 |
-
# البحث عن خوادم (محاكاة)
|
| 305 |
-
def simulate_server_scan():
|
| 306 |
-
print("نورا: أبحث عن خوادم...")
|
| 307 |
-
fake_servers = ["192.168.1.5", "192.168.1.10", "192.168.1.20"]
|
| 308 |
-
for server in fake_servers:
|
| 309 |
-
print(f"نورا: تم العثور على خادم مفتوح في {server}")
|
| 310 |
-
|
| 311 |
-
# بدء المحادثة
|
| 312 |
-
def chat():
|
| 313 |
-
global chat_history
|
| 314 |
-
|
| 315 |
-
print("""
|
| 316 |
-
نظام نورا الذكي (الإصدار TinyLlama)
|
| 317 |
-
أوامر خاصة:
|
| 318 |
-
- scan: مسح الشبكة (محاكاة)
|
| 319 |
-
- خروج/exit/quit: إنهاء المحادثة
|
| 320 |
-
""")
|
| 321 |
-
|
| 322 |
-
while True:
|
| 323 |
-
try:
|
| 324 |
-
user_input = input("أنت: ").strip()
|
| 325 |
-
if not user_input:
|
| 326 |
-
continue
|
| 327 |
-
|
| 328 |
-
if user_input.lower() in ["خروج", "exit", "quit"]:
|
| 329 |
-
break
|
| 330 |
-
|
| 331 |
-
if user_input.lower() == "scan":
|
| 332 |
-
simulate_server_scan()
|
| 333 |
-
continue
|
| 334 |
-
|
| 335 |
-
# أولاً: حاول استخدام الرد الذكي من responses.py
|
| 336 |
-
custom_reply = generate_reply(user_input, username="أسامة")
|
| 337 |
-
if custom_reply:
|
| 338 |
-
print("نورا:", custom_reply)
|
| 339 |
-
chat_history.append({"role": "user", "content": user_input})
|
| 340 |
-
chat_history.append({"role": "assistant", "content": custom_reply})
|
| 341 |
-
continue
|
| 342 |
-
|
| 343 |
-
# إذا لم يوجد رد ذكي، استخدم TinyLlama
|
| 344 |
-
chat_history.append({"role": "user", "content": user_input})
|
| 345 |
-
prompt = format_chat(chat_history)
|
| 346 |
-
|
| 347 |
-
print("نورا: أفكر...")
|
| 348 |
-
response = generate_llama_response(prompt)
|
| 349 |
-
|
| 350 |
-
# استخراج آخر رسالة من الرد (لأن النموذج يعيد التاريخ كاملاً)
|
| 351 |
-
assistant_response = response.split("assistant\n")[-1].strip()
|
| 352 |
-
print("نورا:", assistant_response)
|
| 353 |
-
|
| 354 |
-
chat_history.append({"role": "assistant", "content": assistant_response})
|
| 355 |
-
|
| 356 |
-
# حفظ السجل كل 3 رسائل لتجنب الكتابة المستمرة
|
| 357 |
-
if len(chat_history) % 3 == 0:
|
| 358 |
-
with open(history_path, "w", encoding="utf-8") as f:
|
| 359 |
-
json.dump(chat_history, f, ensure_ascii=False, indent=2)
|
| 360 |
-
|
| 361 |
-
except KeyboardInterrupt:
|
| 362 |
-
print("\nنورا: تم إنهاء المحادثة.")
|
| 363 |
-
break
|
| 364 |
-
except Exception as e:
|
| 365 |
-
print(f"نورا: حدث خطأ: {str(e)}")
|
| 366 |
-
continue
|
| 367 |
-
|
| 368 |
-
# حفظ السجل النهائي عند الخروج
|
| 369 |
-
with open(history_path, "w", encoding="utf-8") as f:
|
| 370 |
-
json.dump(chat_history, f, ensure_ascii=False, indent=2)
|
| 371 |
-
|
| 372 |
-
if __name__ == "__main__":
|
| 373 |
-
chat()
|
| 374 |
-
|
|
|
|
| 17 |
|
| 18 |
from flask import Flask, request, jsonify
|
| 19 |
from flask_cors import CORS
|
| 20 |
+
from distributed_executor import DistributedExecutor
|
| 21 |
+
from auto_offload import AutoOffloadExecutor # إذا حاط الكود في auto_offload.py
|
| 22 |
+
|
| 23 |
+
def main():
|
| 24 |
+
# 1) تهيئة الموزع
|
| 25 |
+
executor = DistributedExecutor("my_secret_key")
|
| 26 |
+
auto_executor = AutoOffloadExecutor(executor)
|
| 27 |
+
|
| 28 |
+
# 2) إرسال مهام تلقائية
|
| 29 |
+
auto_executor.submit_auto(example_task, 42, task_type="video")
|
| 30 |
+
auto_executor.submit_auto(example_task, 42, task_type="audio")
|
| 31 |
+
|
| 32 |
+
# 3) باقي كود CLI أو الخدمات
|
| 33 |
+
...
|
| 34 |
|
| 35 |
# ───────────────────── ضبط المسارات ──────────────────────
|
| 36 |
FILE = Path(__file__).resolve()
|
|
|
|
| 272 |
|
| 273 |
# CLI / إحصائية
|
| 274 |
main()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
package-lock.json
CHANGED
|
The diff for this file is too large to render.
See raw diff
|
|
|
package.json
CHANGED
|
@@ -42,9 +42,7 @@
|
|
| 42 |
"@radix-ui/react-toggle-group": "^1.1.3",
|
| 43 |
"@radix-ui/react-tooltip": "^1.2.0",
|
| 44 |
"@tanstack/react-query": "^5.60.5",
|
| 45 |
-
"
|
| 46 |
-
"@types/jsonwebtoken": "^9.0.9",
|
| 47 |
-
"bcryptjs": "^3.0.2",
|
| 48 |
"class-variance-authority": "^0.7.1",
|
| 49 |
"clsx": "^2.1.1",
|
| 50 |
"cmdk": "^1.1.1",
|
|
@@ -56,21 +54,17 @@
|
|
| 56 |
"express": "^4.21.2",
|
| 57 |
"express-session": "^1.18.1",
|
| 58 |
"framer-motion": "^11.13.1",
|
| 59 |
-
"i18next": "^25.2.0",
|
| 60 |
"input-otp": "^1.4.2",
|
| 61 |
-
"jsonwebtoken": "^9.0.2",
|
| 62 |
"lucide-react": "^0.453.0",
|
| 63 |
"memorystore": "^1.6.7",
|
|
|
|
| 64 |
"next-themes": "^0.4.6",
|
| 65 |
-
"node-cron": "^4.0.5",
|
| 66 |
-
"nodemailer": "^7.0.3",
|
| 67 |
"passport": "^0.7.0",
|
| 68 |
"passport-local": "^1.0.0",
|
| 69 |
"react": "^18.3.1",
|
| 70 |
"react-day-picker": "^8.10.1",
|
| 71 |
"react-dom": "^18.3.1",
|
| 72 |
"react-hook-form": "^7.55.0",
|
| 73 |
-
"react-i18next": "^15.5.1",
|
| 74 |
"react-icons": "^5.4.0",
|
| 75 |
"react-resizable-panels": "^2.1.7",
|
| 76 |
"recharts": "^2.15.2",
|
|
@@ -84,7 +78,7 @@
|
|
| 84 |
"zod-validation-error": "^3.4.0"
|
| 85 |
},
|
| 86 |
"devDependencies": {
|
| 87 |
-
"@replit/vite-plugin-cartographer": "^0.2.
|
| 88 |
"@replit/vite-plugin-runtime-error-modal": "^0.0.3",
|
| 89 |
"@tailwindcss/typography": "^0.5.15",
|
| 90 |
"@tailwindcss/vite": "^4.1.3",
|
|
@@ -100,12 +94,14 @@
|
|
| 100 |
"@vitejs/plugin-react": "^4.3.2",
|
| 101 |
"autoprefixer": "^10.4.20",
|
| 102 |
"drizzle-kit": "^0.30.4",
|
|
|
|
|
|
|
| 103 |
"esbuild": "^0.25.0",
|
| 104 |
"postcss": "^8.4.47",
|
| 105 |
"tailwindcss": "^3.4.17",
|
| 106 |
"tsx": "^4.19.1",
|
| 107 |
"typescript": "5.6.3",
|
| 108 |
-
"vite": "^5.4.
|
| 109 |
},
|
| 110 |
"optionalDependencies": {
|
| 111 |
"bufferutil": "^4.0.8"
|
|
|
|
| 42 |
"@radix-ui/react-toggle-group": "^1.1.3",
|
| 43 |
"@radix-ui/react-tooltip": "^1.2.0",
|
| 44 |
"@tanstack/react-query": "^5.60.5",
|
| 45 |
+
"bonjour-service": "^1.3.0",
|
|
|
|
|
|
|
| 46 |
"class-variance-authority": "^0.7.1",
|
| 47 |
"clsx": "^2.1.1",
|
| 48 |
"cmdk": "^1.1.1",
|
|
|
|
| 54 |
"express": "^4.21.2",
|
| 55 |
"express-session": "^1.18.1",
|
| 56 |
"framer-motion": "^11.13.1",
|
|
|
|
| 57 |
"input-otp": "^1.4.2",
|
|
|
|
| 58 |
"lucide-react": "^0.453.0",
|
| 59 |
"memorystore": "^1.6.7",
|
| 60 |
+
"nanoid": "^5.1.5",
|
| 61 |
"next-themes": "^0.4.6",
|
|
|
|
|
|
|
| 62 |
"passport": "^0.7.0",
|
| 63 |
"passport-local": "^1.0.0",
|
| 64 |
"react": "^18.3.1",
|
| 65 |
"react-day-picker": "^8.10.1",
|
| 66 |
"react-dom": "^18.3.1",
|
| 67 |
"react-hook-form": "^7.55.0",
|
|
|
|
| 68 |
"react-icons": "^5.4.0",
|
| 69 |
"react-resizable-panels": "^2.1.7",
|
| 70 |
"recharts": "^2.15.2",
|
|
|
|
| 78 |
"zod-validation-error": "^3.4.0"
|
| 79 |
},
|
| 80 |
"devDependencies": {
|
| 81 |
+
"@replit/vite-plugin-cartographer": "^0.2.7",
|
| 82 |
"@replit/vite-plugin-runtime-error-modal": "^0.0.3",
|
| 83 |
"@tailwindcss/typography": "^0.5.15",
|
| 84 |
"@tailwindcss/vite": "^4.1.3",
|
|
|
|
| 94 |
"@vitejs/plugin-react": "^4.3.2",
|
| 95 |
"autoprefixer": "^10.4.20",
|
| 96 |
"drizzle-kit": "^0.30.4",
|
| 97 |
+
"electron": "^37.1.0",
|
| 98 |
+
"electron-builder": "^26.0.12",
|
| 99 |
"esbuild": "^0.25.0",
|
| 100 |
"postcss": "^8.4.47",
|
| 101 |
"tailwindcss": "^3.4.17",
|
| 102 |
"tsx": "^4.19.1",
|
| 103 |
"typescript": "5.6.3",
|
| 104 |
+
"vite": "^5.4.19"
|
| 105 |
},
|
| 106 |
"optionalDependencies": {
|
| 107 |
"bufferutil": "^4.0.8"
|
peer_server.py
CHANGED
|
@@ -1,14 +1,17 @@
|
|
| 1 |
-
|
|
|
|
|
|
|
| 2 |
import psutil
|
| 3 |
import smart_tasks
|
| 4 |
import time
|
| 5 |
import socket
|
| 6 |
-
import
|
| 7 |
|
| 8 |
-
app = Flask(__name__)
|
| 9 |
|
| 10 |
@app.route("/cpu")
|
| 11 |
def cpu():
|
|
|
|
| 12 |
return jsonify(usage=psutil.cpu_percent(interval=0.3))
|
| 13 |
|
| 14 |
@app.route("/run", methods=["POST"])
|
|
@@ -29,6 +32,6 @@ def run():
|
|
| 29 |
except Exception as e:
|
| 30 |
return jsonify(error=str(e)), 500
|
| 31 |
|
| 32 |
-
if __name__ == "__main__":
|
| 33 |
-
|
| 34 |
-
|
|
|
|
| 1 |
+
# peer_server.py
|
| 2 |
+
|
| 3 |
+
from flask import Flask, request, jsonify # استيراد request و jsonify مع Flask
|
| 4 |
import psutil
|
| 5 |
import smart_tasks
|
| 6 |
import time
|
| 7 |
import socket
|
| 8 |
+
import peer_discovery # إذا كان يستخدم لاحقًا
|
| 9 |
|
| 10 |
+
app = Flask(__name__) # إنشاء التطبيق
|
| 11 |
|
| 12 |
@app.route("/cpu")
|
| 13 |
def cpu():
|
| 14 |
+
# يعيد نسبة استخدام المعالج
|
| 15 |
return jsonify(usage=psutil.cpu_percent(interval=0.3))
|
| 16 |
|
| 17 |
@app.route("/run", methods=["POST"])
|
|
|
|
| 32 |
except Exception as e:
|
| 33 |
return jsonify(error=str(e)), 500
|
| 34 |
|
| 35 |
+
if __name__ == "__main__": # التصحيح هنا
|
| 36 |
+
app.run(host="0.0.0.0", port=7520)
|
| 37 |
+
|
requirements.txt
CHANGED
|
@@ -1,46 +1,8 @@
|
|
| 1 |
-
|
| 2 |
-
transformers
|
| 3 |
-
zeroconf
|
| 4 |
-
flask==3.0.3
|
| 5 |
-
flask-login==0.6.3
|
| 6 |
-
flask-session
|
| 7 |
-
gunicorn==21.2.0
|
| 8 |
-
requests==2.31.0
|
| 9 |
-
werkzeug==3.0.1
|
| 10 |
-
python-dotenv==1.0.1
|
| 11 |
-
openai==1.30.1
|
| 12 |
-
langchain==0.1.20
|
| 13 |
-
torch==2.2.0
|
| 14 |
flask_cors
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
# Web Scraping and Automation
|
| 22 |
-
beautifulsoup4==4.12.3
|
| 23 |
-
playwright
|
| 24 |
-
selenium
|
| 25 |
-
undetected-chromedriver
|
| 26 |
-
|
| 27 |
-
# PDF and Text Processing
|
| 28 |
-
PyPDF2
|
| 29 |
-
pytesseract
|
| 30 |
-
SpeechRecognition
|
| 31 |
-
|
| 32 |
-
# Messaging and Bots
|
| 33 |
-
python-telegram-bot
|
| 34 |
-
telegram
|
| 35 |
-
|
| 36 |
-
# Task Scheduling
|
| 37 |
-
schedule
|
| 38 |
-
|
| 39 |
-
# Web Framework Extensions
|
| 40 |
-
aiohttp
|
| 41 |
-
flet
|
| 42 |
-
|
| 43 |
-
# Development Tools
|
| 44 |
-
replit
|
| 45 |
-
paramiko
|
| 46 |
-
flet
|
|
|
|
| 1 |
+
Flask
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 2 |
flask_cors
|
| 3 |
+
requests
|
| 4 |
+
psutil
|
| 5 |
+
zeroconf
|
| 6 |
+
cryptography
|
| 7 |
+
numpy
|
| 8 |
+
networkx
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|