diff --git a/Bash b/Bash deleted file mode 100644 index 61d5b59..0000000 --- a/Bash +++ /dev/null @@ -1,55 +0,0 @@ -#!/bin/bash - -# **Section 1: Environment Setup** -echo "### Installing Necessary Packages..." -pip install --upgrade pip -pip install fastapi uvicorn transformers torch torchvision pillow gtts speechrecognition opencv-python-headless openai-whisper loguru pyttsx3 nest_asyncio pyngrok - -echo "### Updating and Installing System Packages..." -sudo apt-get update -sudo apt-get install -y espeak-ng ffmpeg - -# **Section 2: Development Server Setup** -echo "### Starting Uvicorn Server (Development Mode)..." -uvicorn app:app --host 0.0.0.0 --port 8000 & - -# **Optional:** Expose Server using ngrok (for Development) -echo "### Exposing Server with ngrok (Comment out if not needed)..." -# pip install pyngrok -# python -c "from pyngrok import ngrok; public_url = ngrok.connect(8000); print('Public URL:', public_url)" - -# **Section 3: Production Setup with SSL (Comment out for Development)** -# echo "### Generating SSL Certificates (e.g., using Certbot)..." -# certbot certonly --standalone -d yourdomain.com -# -# echo "### Starting Uvicorn Server with SSL (Production Mode)..." -# uvicorn app:app --host 0.0.0.0 --port 8000 --ssl-keyfile=/path/to/key.pem --ssl-certfile=/path/to/cert.pem -# -# **Alternative:** Using Gunicorn for Production -# gunicorn -w 4 -k uvicorn.workers.UvicornWorker main:app --bind 0.0.0.0:8000 - -# **Section 4: API Calls (Development & Testing)** -echo "### Testing API Endpoints (Replace URL and File Paths as Necessary)..." -curl -X POST "http://127.0.0.1:8000/process-nlp/" -H "Content-Type: application/json" -d '{"text": "Hello, how are you?"}' -curl -X POST "http://127.0.0.1:8000/process-cv-detection/" -F "file=@path/to/image.jpg" -curl -X POST "http://127.0.0.1:8000/speech-to-text/" -F "file=@path/to/audio.wav" - -# **Section 5: Version Control (Comment out if not ready for commit)** -# echo "### Initial Commit..." -# git add . -# git commit -m "Initial public release version 1.0.1" -# git push origin main -# -# echo "### Tagging a Release..." -# git tag v1.0.1 -# git push origin --tags - -# **Section 6: Environment Management (Optional)** -# echo "### Creating a Virtual Environment (Comment out if already set)..." -# python -m venv path/to/venv -# # Activate based on your OS (Manual Step) -# # Windows: path\to\venv\Scripts\activate -# # Unix/Linux: source path/to/venv/bin/activate - -# echo "### Installing Additional Tools (e.g., for Arch Linux)..." -# sudo pacman -S python-pipx python-torch diff --git a/JavaScript b/JavaScript deleted file mode 100644 index 8896e21..0000000 --- a/JavaScript +++ /dev/null @@ -1,18 +0,0 @@ -async function fetchData() { - try { - const response = await fetch('https://your-fastapi-server.com/process-nlp/', { - method: 'POST', - headers: { - 'Content-Type': 'application/json', - 'Authorization': 'Bearer YvZz9Hni0hWJPh_UWW4dQYf9rhIe9nNYcC5ZQTTZz0Q' // Replace with your actual secure token - }, - body: JSON.stringify({ text: "Hello FastAPI" }) - }); - const data = await response.json(); - document.getElementById('response').innerText = data.response; - } catch (error) { - document.getElementById('response').innerText = 'Error fetching data'; - } -} - -fetchData(); diff --git a/Unified AGI-style System b/Unified AGI-style System deleted file mode 100644 index 57c2d4f..0000000 --- a/Unified AGI-style System +++ /dev/null @@ -1,208 +0,0 @@ -import os -import logging -import torch -import torch.nn as nn -import torch.nn.functional as F -from torch.utils.data import DataLoader, Dataset -from torchvision import datasets, transforms, models -from transformers import GPT2Model -from fastapi import FastAPI, Request -from torch.optim import AdamW -from torch.amp import GradScaler, autocast # Updated import -from torch.utils.checkpoint import checkpoint -from torch.nn.parallel import DistributedDataParallel as DDP -from torch.distributed import init_process_group, destroy_process_group, is_initialized -from tqdm import tqdm - -# --- Configuration --- -device = torch.device("cuda" if torch.cuda.is_available() else "cpu") -dist_backend = "nccl" if torch.cuda.is_available() else "gloo" -use_distributed = int(os.environ.get("WORLD_SIZE", 1)) > 1 - -# Logging setup -logging.basicConfig(level=logging.INFO, format="%(asctime)s | %(levelname)s | %(message)s") - -# --- Utility: Distributed setup --- -def setup_distributed(): - if use_distributed: - init_process_group(backend=dist_backend) - logging.info(f"Distributed training initialized on rank {os.environ['RANK']}.") - else: - logging.info("Running on a single GPU or CPU.") - -def cleanup_distributed(): - if is_initialized(): - destroy_process_group() - -# --- Text Dataset --- -class TextDataset(Dataset): - def __init__(self, data, tokenizer, max_length=2048): - self.data = data - self.tokenizer = tokenizer - self.max_length = max_length - - def __len__(self): - return len(self.data) - - def __getitem__(self, idx): - item = self.data[idx] - text = item["text"] - encoding = self.tokenizer( - text, padding="max_length", truncation=True, max_length=self.max_length, return_tensors="pt" - ) - input_ids = encoding["input_ids"].squeeze() - attention_mask = encoding["attention_mask"].squeeze() - label = item.get("label", None) - return input_ids, attention_mask, label - -# --- Perception Module --- -class PerceptionModule(nn.Module): - def __init__(self, text_dim, image_dim, sensor_dim, hidden_dim): - super(PerceptionModule, self).__init__() - self.text_model = GPT2Model.from_pretrained("gpt2") - self.text_fc = nn.Linear(self.text_model.config.hidden_size, hidden_dim) - - self.image_model = models.efficientnet_b0(weights='IMAGENET1K_V1') - num_ftrs = self.image_model.classifier[-1].in_features - self.image_model.classifier = nn.Identity() - self.image_fc = nn.Linear(num_ftrs, hidden_dim) - - self.sensor_fc = nn.Linear(sensor_dim, hidden_dim) - self.fc = nn.Linear(hidden_dim * 3, hidden_dim) - - def forward(self, text, image, sensor): - text_features = F.relu(self.text_fc(self.text_model(**text).last_hidden_state.mean(dim=1))) - image_features = F.relu(self.image_fc(self.image_model(image))) - sensor_features = F.relu(self.sensor_fc(sensor)) - combined_features = torch.cat((text_features, image_features, sensor_features), dim=1) - return F.relu(self.fc(combined_features)) - -# --- Memory Module --- -class MemoryBank(nn.Module): - def __init__(self, memory_size, memory_dim): - super(MemoryBank, self).__init__() - self.keys = nn.Parameter(torch.randn(memory_size, memory_dim)) - self.values = nn.Parameter(torch.randn(memory_size, memory_dim)) - self.attention = nn.MultiheadAttention(embed_dim=memory_dim, num_heads=4, batch_first=True) - - def write(self, key, value): - with torch.no_grad(): - idx = torch.argmin(torch.norm(self.keys - key, dim=1)) - self.keys[idx].data.copy_(key) - self.values[idx].data.copy_(value) - - def read(self, key): - query = key.unsqueeze(0) - attn_output, _ = self.attention(query, self.keys.unsqueeze(0), self.values.unsqueeze(0)) - return attn_output.squeeze(0) - -# --- Decision Making Module --- -class DecisionMakingModule(nn.Module): - def __init__(self, input_dim, output_dim): - super(DecisionMakingModule, self).__init__() - self.fc = nn.Linear(input_dim, output_dim) - - def forward(self, features): - return self.fc(features) - -# --- Unified AGI System --- -class UnifiedAGISystem(nn.Module): - def __init__(self, text_dim, image_dim, sensor_dim, hidden_dim, memory_size, output_dim): - super(UnifiedAGISystem, self).__init__() - self.perception = PerceptionModule(text_dim, image_dim, sensor_dim, hidden_dim) - self.memory = MemoryBank(memory_size, hidden_dim) - self.decision_making = DecisionMakingModule(hidden_dim, output_dim) - - def forward(self, text, image, sensor): - features = checkpoint(self.perception, text, image, sensor) - memory_output = self.memory.read(features) - decision = self.decision_making(memory_output) - return decision - - def perform_task(self, text_input, image_tensor, sensor_tensor): - features = checkpoint(self.perception, text_input, image_tensor, sensor_tensor) - self.memory.write(features.detach(), features.detach()) - decision = self.decision_making(features) - return decision - -# --- Training Function --- -def train(model, train_loader, criterion, optimizer, epochs=10, use_amp=True, accumulation_steps=2): - scaler = GradScaler(enabled=use_amp) # Updated line for GradScaler - for epoch in range(epochs): - model.train() - running_loss = 0.0 - optimizer.zero_grad() - - for i, batch in enumerate(tqdm(train_loader)): - images_, labels_ = batch - - dummy_text = { - "input_ids": torch.randint(0, 100, (images_.size(0), 256)).to(device), - "attention_mask": torch.ones((images_.size(0), 256)).to(device), - } - dummy_sensor = torch.randn(images_.size(0), 10).to(device) - - with autocast('cuda', enabled=use_amp): # Updated line for autocast - outputs_ = model(dummy_text, images_.to(device), dummy_sensor) - loss_ = criterion(outputs_, labels_.to(device)) - - scaler.scale(loss_ / accumulation_steps).backward() - - if (i + 1) % accumulation_steps == 0: - scaler.step(optimizer) - scaler.update() - optimizer.zero_grad() - - running_loss += loss_.item() - - logging.info(f"Epoch [{epoch + 1}/{epochs}], Loss: {running_loss / len(train_loader):.4f}") - -# --- Data Augmentation --- -transform = transforms.Compose([ - transforms.RandomHorizontalFlip(), - transforms.RandomCrop(32), - transforms.ToTensor(), - transforms.Normalize(mean=(0.5,), std=(0.5,)) -]) - -# --- Main Execution --- -if __name__ == "__main__": - setup_distributed() - try: - text_dim = 100 - image_dim = (3, 32, 32) - sensor_dim = 10 - hidden_dim = 64 - memory_size = 64 - output_dim = 10 - - agi_system = UnifiedAGISystem(text_dim, image_dim, sensor_dim, hidden_dim, memory_size, output_dim).to(device) - - if use_distributed: - agi_system = DDP(agi_system) - - train_dataset = datasets.CIFAR10(root="./data", train=True, download=True, transform=transform) - train_loader = DataLoader(train_dataset, batch_size=32, shuffle=True) - - criterion = nn.CrossEntropyLoss() - optimizer = AdamW(agi_system.parameters(), lr=0.001) - - train(agi_system, train_loader, criterion, optimizer, epochs=10) - finally: - cleanup_distributed() - -# --- Deployment with FastAPI --- -app = FastAPI() - -@app.post("/predict") -async def predict(request: Request): - data = await request.json() - text_input = { - "input_ids": torch.tensor(data["text"]).to(device), - "attention_mask": torch.tensor(data["mask"]).to(device) - } - image_tensor = torch.tensor(data["image"]).to(device) - sensor_tensor = torch.tensor(data["sensor"]).float().to(device) - - decision = agi_system.perform_task(text_input, image_tensor, sensor_tensor) - return {"decision": decision.tolist()} diff --git a/__pycache__/main.cpython-312.pyc b/__pycache__/main.cpython-312.pyc deleted file mode 100644 index b6f088e..0000000 Binary files a/__pycache__/main.cpython-312.pyc and /dev/null differ diff --git a/__pycache__/test_main_pipeline.cpython-312-pytest-9.1.1.pyc b/__pycache__/test_main_pipeline.cpython-312-pytest-9.1.1.pyc deleted file mode 100644 index c8e4257..0000000 Binary files a/__pycache__/test_main_pipeline.cpython-312-pytest-9.1.1.pyc and /dev/null differ diff --git a/__pycache__/test_nlp_module.cpython-312-pytest-9.1.1.pyc b/__pycache__/test_nlp_module.cpython-312-pytest-9.1.1.pyc deleted file mode 100644 index 011093e..0000000 Binary files a/__pycache__/test_nlp_module.cpython-312-pytest-9.1.1.pyc and /dev/null differ diff --git a/__pycache__/test_regulatory.cpython-312-pytest-9.1.1.pyc b/__pycache__/test_regulatory.cpython-312-pytest-9.1.1.pyc deleted file mode 100644 index 4df3981..0000000 Binary files a/__pycache__/test_regulatory.cpython-312-pytest-9.1.1.pyc and /dev/null differ diff --git a/main.py b/main.py index 0ca0d68..33a5063 100644 --- a/main.py +++ b/main.py @@ -43,6 +43,7 @@ ALGORITHM = "HS256" oauth2_scheme = OAuth2PasswordBearer(tokenUrl="token") + def create_access_token(data: dict): """ Creates a JWT access token. @@ -51,6 +52,7 @@ def create_access_token(data: dict): encoded_jwt = jwt.encode(to_encode, SECRET_KEY, algorithm=ALGORITHM) return encoded_jwt + def authenticate_user(token: str = Depends(oauth2_scheme)): """ Authenticates a user via JWT token. @@ -64,21 +66,25 @@ def authenticate_user(token: str = Depends(oauth2_scheme)): # === Pydantic Models === + class NLPResponse(BaseModel): """Model for NLP Expert responses.""" text: str expert: str + class TextRequest(BaseModel): """Request model for text-based endpoints.""" text: str + class ZKFairnessProof(BaseModel): """Model for Zero-Knowledge Fairness Proofs (MAS FEAT).""" proof_hash: str status: str demographic_parity_score: float + class ContextualAttributionEnvelope(BaseModel): """Model for Contextual Attribution Envelopes (HKMA Ethics).""" attribution_id: str @@ -86,6 +92,7 @@ class ContextualAttributionEnvelope(BaseModel): interpretability_summary: str = "Analysis completed via ASA Interpretability Layer." timestamp: str + class RecursiveContextEnvelope(BaseModel): """Model for Recursive Context Envelopes (EAIP State Management).""" task_lineage: List[str] @@ -93,6 +100,7 @@ class RecursiveContextEnvelope(BaseModel): metadata: dict = {} parent_rce: Optional['RecursiveContextEnvelope'] = None + class TextResponse(BaseModel): """Response model for text-based endpoints.""" response: str @@ -102,8 +110,10 @@ class TextResponse(BaseModel): # === NLP Module (T5 Transformer) === + class NLPModule: """Module for Natural Language Processing using T5 with MoE logic.""" + def __init__(self): model_name = "google/flan-t5-small" self.tokenizer = T5Tokenizer.from_pretrained(model_name) @@ -114,9 +124,19 @@ def __init__(self): def _route_to_expert(self, prompt: str) -> str: """Simulates routing logic to select an expert node.""" lower_prompt = prompt.lower() - if any(word in lower_prompt for word in ["buy", "price", "retail", "shop"]): + if any( + word in lower_prompt for word in [ + "buy", + "price", + "retail", + "shop"]): return "Expert_Retail" - if any(word in lower_prompt for word in ["finance", "stock", "investment", "bank"]): + if any( + word in lower_prompt for word in [ + "finance", + "stock", + "investment", + "bank"]): return "Expert_Finance" return "Expert_General" @@ -127,11 +147,14 @@ def generate_text(self, prompt: str) -> NLPResponse: raise ValueError("Prompt cannot be empty.") try: selected_expert = self._route_to_expert(prompt) - logger.debug(f"Routing to expert: {selected_expert} for prompt: {prompt}") + logger.debug( + f"Routing to expert: {selected_expert} for prompt: {prompt}") inputs = self.tokenizer(prompt, return_tensors="pt").to(device) with torch.no_grad(): - outputs = self.model.generate(inputs["input_ids"], max_length=100) - response = self.tokenizer.decode(outputs[0], skip_special_tokens=True) + outputs = self.model.generate( + inputs["input_ids"], max_length=100) + response = self.tokenizer.decode( + outputs[0], skip_special_tokens=True) logger.info(f"Generated response by {selected_expert}: {response}") return NLPResponse(text=response, expert=selected_expert) except Exception as e: @@ -142,8 +165,10 @@ def generate_text(self, prompt: str) -> NLPResponse: ) from e # === CV Module (YOLOv8 for Object Detection) === + class CVModule: """Module for Computer Vision using YOLOv8.""" + def __init__(self): self.model = YOLO('yolov8n.pt').to(device) logger.info("CV model loaded successfully.") @@ -167,9 +192,14 @@ def detect_objects(self, image: Image.Image) -> str: # === Regulatory Module (Compliance: MAS FEAT & HKMA Ethics) === + class RegulatoryModule: """Module for handling regulatory compliance checks (MAS FEAT & HKMA Ethics).""" - def verify_zk_fairness(self, input_data: str, expert: str = "Unknown") -> ZKFairnessProof: + + def verify_zk_fairness( + self, + input_data: str, + expert: str = "Unknown") -> ZKFairnessProof: """ Simulates ZK-Fairness proof generation for MAS FEAT compliance. Evaluates demographic parity for specific MoE expert nodes. @@ -185,7 +215,8 @@ def verify_zk_fairness(self, input_data: str, expert: str = "Unknown") -> ZKFair variance = (len(input_data) % 5) / 100.0 dp_score = min(1.0, parity_base + variance) - proof_hash = hashlib.sha3_512(f"{input_data}_{expert}".encode()).hexdigest() + proof_hash = hashlib.sha3_512( + f"{input_data}_{expert}".encode()).hexdigest() return ZKFairnessProof( proof_hash=f"zkp_{proof_hash[:32]}", @@ -193,7 +224,10 @@ def verify_zk_fairness(self, input_data: str, expert: str = "Unknown") -> ZKFair demographic_parity_score=dp_score ) - def generate_cae(self, module_name: str, _output: str) -> ContextualAttributionEnvelope: + def generate_cae( + self, + module_name: str, + _output: str) -> ContextualAttributionEnvelope: """ Simulates Contextual Attribution Envelope for HKMA Ethics compliance. Implements an ASA (Adaptive System Attribution) Interpretability Layer. @@ -223,14 +257,18 @@ def generate_cae(self, module_name: str, _output: str) -> ContextualAttributionE ), timestamp=datetime.now(timezone.utc).isoformat() ) + + class SpeechProcessor: """Module for processing speech-to-text and text-to-speech.""" + def __init__(self): self.whisper_model = whisper.load_model("base") try: self.tts = pyttsx3.init() except Exception: - logger.warning("pyttsx3 initialization failed. Text-to-speech will be disabled.") + logger.warning( + "pyttsx3 initialization failed. Text-to-speech will be disabled.") self.tts = None logger.info("Speech processor initialized successfully.") @@ -278,8 +316,10 @@ def text_to_speech(self, text: str) -> None: # === Enhanced AGI Pipeline === + class EnhancedAGIPipeline: """Pipeline orchestrator for multimodal AGI tasks.""" + def __init__(self): self.nlp = NLPModule() self.cv = CVModule() @@ -299,8 +339,10 @@ async def process_nlp(self, text: str) -> dict: nlp_output = await asyncio.to_thread(self.nlp.generate_text, text) response_text = nlp_output.text selected_expert = nlp_output.expert - zk_proof = self.regulatory.verify_zk_fairness(text, expert=selected_expert) - cae_metadata = self.regulatory.generate_cae(f"NLPModule_{selected_expert}", response_text) + zk_proof = self.regulatory.verify_zk_fairness( + text, expert=selected_expert) + cae_metadata = self.regulatory.generate_cae( + f"NLPModule_{selected_expert}", response_text) # Update RCE with results rce.task_lineage.append("NLP_Generated") @@ -327,7 +369,8 @@ async def process_cv(self, image: Image.Image) -> dict: async def process_speech_to_text(self, audio_file: UploadFile) -> dict: """Asynchronously processes speech-to-text requests with compliance checks.""" transcription = await asyncio.to_thread(self.speech_processor.speech_to_text, audio_file) - cae_metadata = self.regulatory.generate_cae("SpeechProcessor", transcription) + cae_metadata = self.regulatory.generate_cae( + "SpeechProcessor", transcription) return { "response": transcription, "cae_metadata": cae_metadata @@ -337,6 +380,7 @@ async def process_text_to_speech(self, text: str) -> None: """Asynchronously processes text-to-speech requests.""" await asyncio.to_thread(self.speech_processor.text_to_speech, text) + # === FastAPI Application === app = FastAPI() app.add_middleware( @@ -351,22 +395,27 @@ async def process_text_to_speech(self, text: str) -> None: # === Graceful Shutdown === + def shutdown_signal_handler(sig, frame): """Handles system signals for graceful shutdown.""" # pylint: disable=unused-argument print('Shutting down gracefully...') sys.exit(0) + signal.signal(signal.SIGINT, shutdown_signal_handler) signal.signal(signal.SIGTERM, shutdown_signal_handler) # === Endpoints === + + @app.post("/process-nlp/", response_model=TextResponse, dependencies=[Depends(authenticate_user)]) async def process_nlp(request: TextRequest): """Endpoint for generating text responses.""" return await pipeline.process_nlp(request.text) + @app.post("/process-cv-detection/", dependencies=[Depends(authenticate_user)]) async def process_cv_detection(file: UploadFile): @@ -374,6 +423,7 @@ async def process_cv_detection(file: UploadFile): image = Image.open(io.BytesIO(await file.read())) return await pipeline.process_cv(image) + @app.post("/batch-cv-detection/", dependencies=[Depends(authenticate_user)]) async def batch_cv_detection(files: List[UploadFile]): @@ -382,12 +432,14 @@ async def batch_cv_detection(files: List[UploadFile]): responses = await asyncio.gather(*tasks) return {"batch_detections": responses} + @app.post("/speech-to-text/", response_model=TextResponse, dependencies=[Depends(authenticate_user)]) async def speech_to_text(file: UploadFile): """Endpoint for speech-to-text transcription.""" return await pipeline.process_speech_to_text(file) + @app.post("/text-to-speech/", dependencies=[Depends(authenticate_user)]) async def text_to_speech(request: TextRequest): """Endpoint for text-to-speech synthesis.""" diff --git a/main.yml b/main.yml index eed211e..d389bf9 100644 --- a/main.yml +++ b/main.yml @@ -14,32 +14,40 @@ jobs: steps: - name: Checkout code - uses: actions/checkout@v2 + uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4.1.7 - name: Set up Python - uses: actions/setup-python@v2 + uses: actions/setup-python@39cd14951b08e74b54015e9e001cdefcf80e669f # v5.1.1 with: python-version: '3.10' + - name: Install system dependencies + run: | + sudo apt-get update + sudo apt-get install -y ffmpeg espeak-ng + - name: Install dependencies run: | python -m pip install --upgrade pip - pip install fastapi uvicorn transformers torch torchvision pillow gtts speechrecognition opencv-python-headless openai-whisper loguru pyttsx3 nest_asyncio + if [ -f requirements.txt ]; then pip install -r requirements.txt; fi + pip install flake8 pytest pytest-asyncio + + - name: Generate test audio + run: | + ffmpeg -f lavfi -i anullsrc=r=16000:cl=mono -t 1 -y test.wav - name: Run tests run: | - # Add your test commands here, e.g., pytest - echo "No tests specified" + pytest - name: Lint with flake8 run: | - pip install flake8 - flake8 . + flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics + flake8 . --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics - name: Deploy to Server if: github.ref == 'refs/heads/main' run: | - # Add your deployment commands here, e.g., using scp or rsync echo "Deployment step (e.g., SCP, Rsync)" - name: Notify Deployment Success diff --git a/pipeline_2026-06-19_16-00-50_623569.log b/pipeline_2026-06-19_16-00-50_623569.log deleted file mode 100644 index 5e8892c..0000000 --- a/pipeline_2026-06-19_16-00-50_623569.log +++ /dev/null @@ -1,28 +0,0 @@ -2026-06-19 16:00:50.634 | INFO | main::39 - Application startup -2026-06-19 16:00:51.622 | INFO | main:__init__:112 - NLP model and MoE experts loaded successfully. -2026-06-19 16:00:51.687 | INFO | main:__init__:149 - CV model loaded successfully. -2026-06-19 16:00:53.037 | INFO | main:__init__:235 - Speech processor initialized successfully. -2026-06-19 16:00:54.277 | INFO | main:__init__:112 - NLP model and MoE experts loaded successfully. -2026-06-19 16:00:54.277 | DEBUG | main:generate_text:130 - Routing to expert: Expert_Finance for prompt: What are the best finance investments? -2026-06-19 16:00:54.395 | INFO | main:generate_text:135 - Generated response by Expert_Finance: a financial institution -2026-06-19 16:00:55.161 | INFO | main:__init__:112 - NLP model and MoE experts loaded successfully. -2026-06-19 16:00:55.161 | DEBUG | main:generate_text:130 - Routing to expert: Expert_General for prompt: Hello there! -2026-06-19 16:00:55.250 | INFO | main:generate_text:135 - Generated response by Expert_General: Hello there! -2026-06-19 16:00:56.289 | INFO | main:__init__:112 - NLP model and MoE experts loaded successfully. -2026-06-19 16:00:56.290 | DEBUG | main:generate_text:130 - Routing to expert: Expert_Retail for prompt: Where can I buy retail stock? -2026-06-19 16:00:56.396 | INFO | main:generate_text:135 - Generated response by Expert_Retail: a retail store -2026-06-19 16:00:57.206 | INFO | main:__init__:112 - NLP model and MoE experts loaded successfully. -2026-06-19 16:00:57.265 | INFO | main:__init__:149 - CV model loaded successfully. -2026-06-19 16:00:58.619 | INFO | main:__init__:235 - Speech processor initialized successfully. -2026-06-19 16:00:58.620 | DEBUG | main:generate_text:130 - Routing to expert: Expert_Retail for prompt: I want to buy some retail items -2026-06-19 16:00:58.959 | INFO | main:generate_text:135 - Generated response by Expert_Retail: I want to buy some retail items -2026-06-19 16:01:00.065 | INFO | main:__init__:112 - NLP model and MoE experts loaded successfully. -2026-06-19 16:01:00.123 | INFO | main:__init__:149 - CV model loaded successfully. -2026-06-19 16:01:01.466 | INFO | main:__init__:235 - Speech processor initialized successfully. -2026-06-19 16:01:01.467 | DEBUG | main:detect_objects:156 - Detecting objects in the image. -2026-06-19 16:01:01.825 | INFO | main:detect_objects:159 - Object detection completed successfully. -2026-06-19 16:01:02.650 | INFO | main:__init__:112 - NLP model and MoE experts loaded successfully. -2026-06-19 16:01:02.704 | INFO | main:__init__:149 - CV model loaded successfully. -2026-06-19 16:01:04.017 | INFO | main:__init__:235 - Speech processor initialized successfully. -2026-06-19 16:01:04.018 | DEBUG | main:speech_to_text:243 - Processing speech-to-text. -2026-06-19 16:01:05.509 | INFO | main:speech_to_text:246 - Speech-to-text conversion completed successfully. diff --git a/test_cv_module.py b/test_cv_module.py index 0052b31..b9b1fa7 100644 --- a/test_cv_module.py +++ b/test_cv_module.py @@ -2,13 +2,14 @@ from PIL import Image from main import CVModule + class TestCVModule(unittest.TestCase): def setUp(self): self.cv = CVModule() def test_detect_objects(self): # Create a dummy image for testing - image = Image.new('RGB', (100, 100), color = 'white') + image = Image.new('RGB', (100, 100), color='white') result = self.cv.detect_objects(image) self.assertIsNotNone(result) self.assertIsInstance(result, str) @@ -17,5 +18,6 @@ def test_detect_objects_invalid_image(self): with self.assertRaises(ValueError): self.cv.detect_objects(None) + if __name__ == '__main__': unittest.main() diff --git a/test_main_endpoints.py b/test_main_endpoints.py index 671b74c..1627bbb 100644 --- a/test_main_endpoints.py +++ b/test_main_endpoints.py @@ -6,36 +6,50 @@ client = TestClient(app) + @pytest.fixture def auth_header(): token = create_access_token({"sub": "testuser"}) return {"Authorization": f"Bearer {token}"} + def test_nlp_endpoint(auth_header): - response = client.post("/process-nlp/", json={"text": "test"}, headers=auth_header) + response = client.post( + "/process-nlp/", + json={ + "text": "test"}, + headers=auth_header) assert response.status_code == 200 data = response.json() assert "response" in data assert "zk_proof" in data assert "cae_metadata" in data + def test_cv_endpoint(auth_header): - image = Image.new('RGB', (100, 100), color = 'white') + image = Image.new('RGB', (100, 100), color='white') img_byte_arr = io.BytesIO() image.save(img_byte_arr, format='PNG') img_byte_arr.seek(0) files = {'file': ('test.png', img_byte_arr, 'image/png')} - response = client.post("/process-cv-detection/", files=files, headers=auth_header) + response = client.post( + "/process-cv-detection/", + files=files, + headers=auth_header) assert response.status_code == 200 data = response.json() assert "detections" in data assert "cae_metadata" in data + def test_stt_endpoint(auth_header): with open("test.wav", "rb") as f: files = {'file': ('test.wav', f, 'audio/wav')} - response = client.post("/speech-to-text/", files=files, headers=auth_header) + response = client.post( + "/speech-to-text/", + files=files, + headers=auth_header) assert response.status_code == 200 data = response.json() assert "response" in data diff --git a/test_main_pipeline.py b/test_main_pipeline.py index 11f2a2b..84ecfcd 100644 --- a/test_main_pipeline.py +++ b/test_main_pipeline.py @@ -1,8 +1,9 @@ import pytest -from main import EnhancedAGIPipeline, TextResponse +from main import EnhancedAGIPipeline from PIL import Image import io + @pytest.mark.asyncio async def test_pipeline_nlp(): pipeline = EnhancedAGIPipeline() @@ -13,14 +14,16 @@ async def test_pipeline_nlp(): assert result["zk_proof"].status == "VERIFIED" assert "Expert_Retail" in result["cae_metadata"].interpretability_summary + @pytest.mark.asyncio async def test_pipeline_cv(): pipeline = EnhancedAGIPipeline() - image = Image.new('RGB', (100, 100), color = 'white') + image = Image.new('RGB', (100, 100), color='white') result = await pipeline.process_cv(image) assert "detections" in result assert "cae_metadata" in result + @pytest.mark.asyncio async def test_pipeline_stt(): pipeline = EnhancedAGIPipeline() diff --git a/test_nlp_module.py b/test_nlp_module.py index 7209141..cc41471 100644 --- a/test_nlp_module.py +++ b/test_nlp_module.py @@ -1,6 +1,7 @@ import unittest from main import NLPModule + class TestNLPModule(unittest.TestCase): def setUp(self): self.nlp = NLPModule() @@ -21,5 +22,6 @@ def test_generate_text_general(self): result = self.nlp.generate_text(prompt) self.assertEqual(result.expert, "Expert_General") + if __name__ == '__main__': unittest.main() diff --git a/test_regulatory.py b/test_regulatory.py index ae8aaff..835be40 100644 --- a/test_regulatory.py +++ b/test_regulatory.py @@ -1,13 +1,15 @@ import unittest from main import RegulatoryModule, ZKFairnessProof, ContextualAttributionEnvelope + class TestRegulatoryModule(unittest.TestCase): def setUp(self): self.regulatory = RegulatoryModule() def test_verify_zk_fairness(self): input_text = "test input" - result = self.regulatory.verify_zk_fairness(input_text, expert="Expert_Retail") + result = self.regulatory.verify_zk_fairness( + input_text, expert="Expert_Retail") self.assertIsInstance(result, ZKFairnessProof) self.assertIn(result.status, ["VERIFIED", "FAILED"]) # Based on new logic: 0.92 + (10 % 5) / 100 = 0.92 @@ -15,13 +17,19 @@ def test_verify_zk_fairness(self): self.assertTrue(result.proof_hash.startswith("zkp_")) def test_generate_cae_nlp(self): - result = self.regulatory.generate_cae("NLPModule_Expert_Retail", "test output") + result = self.regulatory.generate_cae( + "NLPModule_Expert_Retail", "test output") self.assertIsInstance(result, ContextualAttributionEnvelope) - # NLPModule_Expert_Retail -> ExpertNode_Retail (split by _ and take last) + # NLPModule_Expert_Retail -> ExpertNode_Retail (split by _ and take + # last) self.assertIn("ExpertNode_Retail", result.contribution_scores) self.assertEqual(result.contribution_scores["ExpertNode_Retail"], 0.75) - self.assertIn("NLPModule_Expert_Retail", result.interpretability_summary) - self.assertIn("ASA Interpretability Layer", result.interpretability_summary) + self.assertIn( + "NLPModule_Expert_Retail", + result.interpretability_summary) + self.assertIn( + "ASA Interpretability Layer", + result.interpretability_summary) def test_generate_cae_cv(self): result = self.regulatory.generate_cae("CVModule", "test detections") @@ -30,5 +38,6 @@ def test_generate_cae_cv(self): self.assertEqual(result.contribution_scores["CVModule"], 0.80) self.assertIn("CVModule", result.interpretability_summary) + if __name__ == '__main__': unittest.main() diff --git a/test_speech_processor.py b/test_speech_processor.py index 3d513a8..569c7f0 100644 --- a/test_speech_processor.py +++ b/test_speech_processor.py @@ -2,7 +2,7 @@ from io import BytesIO from fastapi import UploadFile from main import SpeechProcessor -import os + class TestSpeechProcessor(unittest.TestCase): def setUp(self): @@ -26,5 +26,6 @@ def test_text_to_speech_empty_text(self): with self.assertRaises(ValueError): self.speech_processor.text_to_speech("") + if __name__ == '__main__': unittest.main() diff --git a/yaml b/yaml deleted file mode 100644 index eafb2ff..0000000 --- a/yaml +++ /dev/null @@ -1,39 +0,0 @@ -name: CI/CD Pipeline - -on: - push: - branches: - - main - -jobs: - build: - runs-on: ubuntu-latest - - steps: - - uses: actions/checkout@v2 - - name: Set up Python - uses: actions/setup-python@v2 - with: - python-version: '3.10' - - name: Install dependencies - run: | - python -m pip install --upgrade pip - pip install -r requirements.txt - - name: Run tests - run: | - pytest - - docker_build: - runs-on: ubuntu-latest - needs: build - - steps: - - uses: actions/checkout@v2 - - name: Build Docker image - run: | - docker build -t agi-pipeline:1.0.1 . - - name: Push to Docker Hub - run: | - docker tag agi-pipeline:1.0.1 yourdockerhubusername/agi-pipeline:1.0.1 - echo "${{ secrets.DOCKER_PASSWORD }}" | docker login -u "${{ secrets.DOCKER_USERNAME }}" --password-stdin - docker push yourdockerhubusername/agi-pipeline:1.0.1 diff --git a/yolov8n.pt b/yolov8n.pt deleted file mode 100644 index 0db4ca4..0000000 Binary files a/yolov8n.pt and /dev/null differ