Pujan-Dev commited on
Commit
4d6298c
·
1 Parent(s): 0b891ac

fixed :changed everything config

Browse files
config.py CHANGED
@@ -13,3 +13,33 @@ class Config:
13
  REPO_ID_LANG = os.getenv("English_model") or "Pujan-Dev/Ai_vs_HUMAN"
14
  LANG_MODEL = os.getenv("LANG_MODEL")
15
  HF_TOKEN = os.getenv("HF_TOKEN") or os.getenv("HUGGINGFACE_TOKEN")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
13
  REPO_ID_LANG = os.getenv("English_model") or "Pujan-Dev/Ai_vs_HUMAN"
14
  LANG_MODEL = os.getenv("LANG_MODEL")
15
  HF_TOKEN = os.getenv("HF_TOKEN") or os.getenv("HUGGINGFACE_TOKEN")
16
+ SECRET_TOKEN = os.getenv("MY_SECRET_TOKEN")
17
+
18
+ IMAGE_CLASSIFIER_REPO_ID = os.getenv("IMAGE_CLASSIFIER_REPO_ID", "can-org/AI-VS-HUMAN-IMAGE-classifier")
19
+ IMAGE_CLASSIFIER_MODEL_DIR = os.getenv("IMAGE_CLASSIFIER_MODEL_DIR", "./IMG_Models")
20
+ IMAGE_CLASSIFIER_WEIGHTS_FILE = os.getenv("IMAGE_CLASSIFIER_WEIGHTS_FILE", "latest-my_cnn_model.h5")
21
+
22
+ AI_HUMAN_CLIP_MODEL_NAME = os.getenv("AI_HUMAN_CLIP_MODEL_NAME", "ViT-L/14")
23
+ AI_HUMAN_SVM_REPO_ID = os.getenv("AI_HUMAN_SVM_REPO_ID", "rhnsa/ai_human_image_detector")
24
+ AI_HUMAN_SVM_FILENAME = os.getenv("AI_HUMAN_SVM_FILENAME", "svm_model_real.joblib")
25
+
26
+ REAL_FORGED_MODEL_REPO_ID = os.getenv("REAL_FORGED_MODEL_REPO_ID", "rhnsa/real_forged_classifier")
27
+ REAL_FORGED_MODEL_FILENAME = os.getenv("REAL_FORGED_MODEL_FILENAME", "fft_cnn_model_78.pth")
28
+
29
+ RAG_CHROMA_HOST = os.getenv("CHROMA_HOST", "localhost")
30
+ RAG_CHROMA_PORT = int(os.getenv("CHROMA_PORT", "8000"))
31
+ RAG_COLLECTION_NAME = os.getenv("RAG_COLLECTION_NAME", "company_docs_collection")
32
+
33
+ RAG_LLM_PROVIDER = os.getenv("LLM_PROVIDER", "openai").lower()
34
+ RAG_LLM_API_KEY = os.getenv("LLM_API_KEY")
35
+ RAG_LLM_MODEL = os.getenv("LLM_MODEL", "gpt-3.5-turbo")
36
+ RAG_LLM_TEMPERATURE = float(os.getenv("LLM_TEMPERATURE", "0"))
37
+ RAG_LLM_MAX_TOKENS = int(os.getenv("LLM_MAX_TOKENS", "2048"))
38
+
39
+ RAG_MAX_FILE_SIZE = int(os.getenv("RAG_MAX_FILE_SIZE", str(100 * 1024 * 1024)))
40
+ RAG_MAX_QUERY_LENGTH = int(os.getenv("RAG_MAX_QUERY_LENGTH", "1000"))
41
+ RAG_SUPPORTED_CONTENT_TYPES = {
42
+ "application/pdf",
43
+ "application/vnd.openxmlformats-officedocument.wordprocessingml.document",
44
+ "text/plain",
45
+ }
features/ai_human_image_classifier/model_loader.py CHANGED
@@ -69,9 +69,9 @@ class ModelLoader:
69
 
70
  # --- Global Model Instance ---
71
  # This creates a single instance of the models that can be imported by other modules.
72
- CLIP_MODEL_NAME = 'ViT-L/14'
73
- SVM_REPO_ID = 'rhnsa/ai_human_image_detector'
74
- SVM_FILENAME = 'svm_model_real.joblib' # The name of your model file in the Hugging Face repo
75
 
76
  # This instance will be created when the application starts.
77
  models = ModelLoader(
 
69
 
70
  # --- Global Model Instance ---
71
  # This creates a single instance of the models that can be imported by other modules.
72
+ CLIP_MODEL_NAME = Config.AI_HUMAN_CLIP_MODEL_NAME
73
+ SVM_REPO_ID = Config.AI_HUMAN_SVM_REPO_ID
74
+ SVM_FILENAME = Config.AI_HUMAN_SVM_FILENAME
75
 
76
  # This instance will be created when the application starts.
77
  models = ModelLoader(
features/image_classifier/model_loader.py CHANGED
@@ -4,12 +4,13 @@ import logging
4
  import tensorflow as tf
5
  from tensorflow.keras.layers import Layer
6
  from huggingface_hub import snapshot_download
 
7
 
8
  # Model config
9
- REPO_ID = "can-org/AI-VS-HUMAN-IMAGE-classifier"
10
- MODEL_DIR = "./IMG_Models"
11
- WEIGHTS_PATH = os.path.join(MODEL_DIR, "latest-my_cnn_model.h5")
12
- HF_TOKEN = os.getenv("HF_TOKEN") or os.getenv("HUGGINGFACE_TOKEN")
13
 
14
  # Device info (for logging)
15
  gpus = tf.config.list_physical_devices("GPU")
 
4
  import tensorflow as tf
5
  from tensorflow.keras.layers import Layer
6
  from huggingface_hub import snapshot_download
7
+ from config import Config
8
 
9
  # Model config
10
+ REPO_ID = Config.IMAGE_CLASSIFIER_REPO_ID
11
+ MODEL_DIR = Config.IMAGE_CLASSIFIER_MODEL_DIR
12
+ WEIGHTS_PATH = os.path.join(MODEL_DIR, Config.IMAGE_CLASSIFIER_WEIGHTS_FILE)
13
+ HF_TOKEN = Config.HF_TOKEN
14
 
15
  # Device info (for logging)
16
  gpus = tf.config.list_physical_devices("GPU")
features/image_edit_detector/controller.py CHANGED
@@ -7,8 +7,9 @@ from .detectors.ela import run_ela
7
  from .preprocess import preprocess_image
8
  from fastapi import HTTPException,status,Depends
9
  from fastapi.security import HTTPBearer, HTTPAuthorizationCredentials
 
10
  security=HTTPBearer()
11
- import os
12
  async def process_image_ela(image_bytes: bytes, quality: int=90):
13
  image = Image.open(io.BytesIO(image_bytes))
14
 
@@ -40,7 +41,7 @@ async def process_meta_image(image_bytes: bytes) -> dict:
40
 
41
  async def verify_token(credentials: HTTPAuthorizationCredentials = Depends(security)):
42
  token = credentials.credentials
43
- expected_token = os.getenv("MY_SECRET_TOKEN")
44
  if token != expected_token:
45
  raise HTTPException(
46
  status_code=status.HTTP_403_FORBIDDEN,
 
7
  from .preprocess import preprocess_image
8
  from fastapi import HTTPException,status,Depends
9
  from fastapi.security import HTTPBearer, HTTPAuthorizationCredentials
10
+ from config import Config
11
  security=HTTPBearer()
12
+
13
  async def process_image_ela(image_bytes: bytes, quality: int=90):
14
  image = Image.open(io.BytesIO(image_bytes))
15
 
 
41
 
42
  async def verify_token(credentials: HTTPAuthorizationCredentials = Depends(security)):
43
  token = credentials.credentials
44
+ expected_token = Config.SECRET_TOKEN
45
  if token != expected_token:
46
  raise HTTPException(
47
  status_code=status.HTTP_403_FORBIDDEN,
features/nepali_text_classifier/controller.py CHANGED
@@ -3,7 +3,7 @@ import logging
3
  from io import BytesIO
4
  from fastapi import HTTPException, UploadFile, status, Depends
5
  from fastapi.security import HTTPBearer, HTTPAuthorizationCredentials
6
- import os
7
  from features.nepali_text_classifier.inferencer import classify_text
8
  from features.nepali_text_classifier.preprocess import *
9
  import re
@@ -25,7 +25,7 @@ def contains_english(text: str) -> bool:
25
 
26
  async def verify_token(credentials: HTTPAuthorizationCredentials = Depends(security)):
27
  token = credentials.credentials
28
- expected_token = os.getenv("MY_SECRET_TOKEN")
29
  if token != expected_token:
30
  raise HTTPException(
31
  status_code=status.HTTP_403_FORBIDDEN,
 
3
  from io import BytesIO
4
  from fastapi import HTTPException, UploadFile, status, Depends
5
  from fastapi.security import HTTPBearer, HTTPAuthorizationCredentials
6
+ from config import Config
7
  from features.nepali_text_classifier.inferencer import classify_text
8
  from features.nepali_text_classifier.preprocess import *
9
  import re
 
25
 
26
  async def verify_token(credentials: HTTPAuthorizationCredentials = Depends(security)):
27
  token = credentials.credentials
28
+ expected_token = Config.SECRET_TOKEN
29
  if token != expected_token:
30
  raise HTTPException(
31
  status_code=status.HTTP_403_FORBIDDEN,
features/rag_chatbot/controller.py CHANGED
@@ -1,11 +1,10 @@
1
- import os
2
  import asyncio
3
  import logging
4
- from io import BytesIO
5
  from typing import Dict, Any
6
 
7
  from fastapi import HTTPException, UploadFile, status, Depends
8
  from fastapi.security import HTTPBearer, HTTPAuthorizationCredentials
 
9
 
10
  from .rag_pipeline import route_and_process_query, add_document_to_rag, check_system_health
11
  from .document_handler import extract_text_from_file
@@ -17,18 +16,15 @@ logger = logging.getLogger(__name__)
17
  security = HTTPBearer()
18
 
19
  # Supported file types
20
- SUPPORTED_CONTENT_TYPES = {
21
- "application/pdf",
22
- "application/vnd.openxmlformats-officedocument.wordprocessingml.document",
23
- "text/plain"
24
- }
25
 
26
- MAX_FILE_SIZE = 100 * 1024 * 1024 # 100MB
 
27
 
28
  async def verify_token(credentials: HTTPAuthorizationCredentials = Depends(security)):
29
  """Verify Bearer token from Authorization header."""
30
  token = credentials.credentials
31
- expected_token = os.getenv("MY_SECRET_TOKEN")
32
 
33
  if not expected_token:
34
  logger.error("MY_SECRET_TOKEN not configured")
@@ -55,10 +51,10 @@ async def handle_rag_query(query: str) -> Dict[str, Any]:
55
  detail="Query cannot be empty"
56
  )
57
 
58
- if len(query) > 1000: # Reasonable limit
59
  raise HTTPException(
60
  status_code=status.HTTP_400_BAD_REQUEST,
61
- detail="Query too long. Please limit to 1000 characters."
62
  )
63
 
64
  try:
 
 
1
  import asyncio
2
  import logging
 
3
  from typing import Dict, Any
4
 
5
  from fastapi import HTTPException, UploadFile, status, Depends
6
  from fastapi.security import HTTPBearer, HTTPAuthorizationCredentials
7
+ from config import Config
8
 
9
  from .rag_pipeline import route_and_process_query, add_document_to_rag, check_system_health
10
  from .document_handler import extract_text_from_file
 
16
  security = HTTPBearer()
17
 
18
  # Supported file types
19
+ SUPPORTED_CONTENT_TYPES = Config.RAG_SUPPORTED_CONTENT_TYPES
 
 
 
 
20
 
21
+ MAX_FILE_SIZE = Config.RAG_MAX_FILE_SIZE
22
+ MAX_QUERY_LENGTH = Config.RAG_MAX_QUERY_LENGTH
23
 
24
  async def verify_token(credentials: HTTPAuthorizationCredentials = Depends(security)):
25
  """Verify Bearer token from Authorization header."""
26
  token = credentials.credentials
27
+ expected_token = Config.SECRET_TOKEN
28
 
29
  if not expected_token:
30
  logger.error("MY_SECRET_TOKEN not configured")
 
51
  detail="Query cannot be empty"
52
  )
53
 
54
+ if len(query) > MAX_QUERY_LENGTH:
55
  raise HTTPException(
56
  status_code=status.HTTP_400_BAD_REQUEST,
57
+ detail=f"Query too long. Please limit to {MAX_QUERY_LENGTH} characters."
58
  )
59
 
60
  try:
features/rag_chatbot/rag_pipeline.py CHANGED
@@ -10,20 +10,22 @@ from langchain_community.vectorstores import Chroma
10
  from langchain.chains import LLMChain
11
  from langchain.prompts import PromptTemplate
12
  from langchain.chat_models import ChatOpenAI
 
13
 
14
 
15
  load_dotenv()
16
 
17
  # ChromaDB configuration
18
- CHROMA_HOST = os.getenv("CHROMA_HOST", "localhost") # change in env in production when hosted
19
- COLLECTION_NAME = "company_docs_collection"
 
20
 
21
  # LLM Provider Configuration
22
- LLM_PROVIDER = os.getenv("LLM_PROVIDER", "openai").lower()
23
- LLM_API_KEY = os.getenv("LLM_API_KEY")
24
- LLM_MODEL = os.getenv("LLM_MODEL", "gpt-3.5-turbo")
25
- LLM_TEMPERATURE = float(os.getenv("LLM_TEMPERATURE", "0"))
26
- LLM_MAX_TOKENS = int(os.getenv("LLM_MAX_TOKENS", "2048"))
27
 
28
  # Provider-specific configurations
29
  PROVIDER_CONFIGS = {
@@ -93,7 +95,7 @@ def initialize_pipelines():
93
 
94
  # Initialize ChromaDB client
95
  try:
96
- chroma_client = chromadb.HttpClient(host=CHROMA_HOST, port=8000)
97
  chroma_client.heartbeat()
98
  except Exception as e:
99
  raise ConnectionError("Failed to connect to ChromaDB.") from e
 
10
  from langchain.chains import LLMChain
11
  from langchain.prompts import PromptTemplate
12
  from langchain.chat_models import ChatOpenAI
13
+ from config import Config
14
 
15
 
16
  load_dotenv()
17
 
18
  # ChromaDB configuration
19
+ CHROMA_HOST = Config.RAG_CHROMA_HOST
20
+ CHROMA_PORT = Config.RAG_CHROMA_PORT
21
+ COLLECTION_NAME = Config.RAG_COLLECTION_NAME
22
 
23
  # LLM Provider Configuration
24
+ LLM_PROVIDER = Config.RAG_LLM_PROVIDER
25
+ LLM_API_KEY = Config.RAG_LLM_API_KEY
26
+ LLM_MODEL = Config.RAG_LLM_MODEL
27
+ LLM_TEMPERATURE = Config.RAG_LLM_TEMPERATURE
28
+ LLM_MAX_TOKENS = Config.RAG_LLM_MAX_TOKENS
29
 
30
  # Provider-specific configurations
31
  PROVIDER_CONFIGS = {
 
95
 
96
  # Initialize ChromaDB client
97
  try:
98
+ chroma_client = chromadb.HttpClient(host=CHROMA_HOST, port=CHROMA_PORT)
99
  chroma_client.heartbeat()
100
  except Exception as e:
101
  raise ConnectionError("Failed to connect to ChromaDB.") from e
features/rag_chatbot/routes.py CHANGED
@@ -4,7 +4,7 @@ from pydantic import BaseModel, Field
4
  from slowapi.util import get_remote_address
5
  from slowapi import Limiter
6
  from typing import Optional
7
- from config import ACCESS_RATE
8
  from .controller import (
9
  handle_rag_query,
10
  handle_document_upload,
@@ -101,11 +101,7 @@ async def get_system_info(request: Request):
101
  "Cybersecurity knowledge and best practices",
102
  "Document upload and processing (PDF, DOCX, TXT)"
103
  ],
104
- "supported_file_types": [
105
- "application/pdf",
106
- "application/vnd.openxmlformats-officedocument.wordprocessingml.document",
107
- "text/plain"
108
- ],
109
- "max_file_size_mb": 10,
110
- "max_query_length": 1000
111
  }
 
4
  from slowapi.util import get_remote_address
5
  from slowapi import Limiter
6
  from typing import Optional
7
+ from config import ACCESS_RATE, Config
8
  from .controller import (
9
  handle_rag_query,
10
  handle_document_upload,
 
101
  "Cybersecurity knowledge and best practices",
102
  "Document upload and processing (PDF, DOCX, TXT)"
103
  ],
104
+ "supported_file_types": sorted(Config.RAG_SUPPORTED_CONTENT_TYPES),
105
+ "max_file_size_mb": round(Config.RAG_MAX_FILE_SIZE / (1024 * 1024), 2),
106
+ "max_query_length": Config.RAG_MAX_QUERY_LENGTH
 
 
 
 
107
  }
features/real_forged_classifier/model_loader.py CHANGED
@@ -55,7 +55,7 @@ class ModelLoader:
55
  raise
56
 
57
  # --- Global Model Instance ---
58
- MODEL_REPO_ID = 'rhnsa/real_forged_classifier'
59
- MODEL_FILENAME = 'fft_cnn_model_78.pth'
60
  models = ModelLoader(model_repo_id=MODEL_REPO_ID, model_filename=MODEL_FILENAME)
61
 
 
55
  raise
56
 
57
  # --- Global Model Instance ---
58
+ MODEL_REPO_ID = Config.REAL_FORGED_MODEL_REPO_ID
59
+ MODEL_FILENAME = Config.REAL_FORGED_MODEL_FILENAME
60
  models = ModelLoader(model_repo_id=MODEL_REPO_ID, model_filename=MODEL_FILENAME)
61
 
features/text_classifier/controller.py CHANGED
@@ -1,10 +1,10 @@
1
  import asyncio
2
  import logging
3
- import os
4
  from io import BytesIO
5
 
6
  from fastapi import Depends, HTTPException, UploadFile, status
7
  from fastapi.security import HTTPAuthorizationCredentials, HTTPBearer
 
8
 
9
  from .inferencer import analyze_text_with_sentences, classify_text
10
  from .preprocess import parse_docx, parse_pdf, parse_txt
@@ -33,7 +33,7 @@ def build_bias_summary(ai_likelihood: float) -> dict[str, object]:
33
  # Verify Bearer token from Authorization header
34
  async def verify_token(credentials: HTTPAuthorizationCredentials = Depends(security)):
35
  token = credentials.credentials
36
- expected_token = os.getenv("MY_SECRET_TOKEN")
37
  if token != expected_token:
38
  raise HTTPException(
39
  status_code=status.HTTP_403_FORBIDDEN, detail="Invalid or expired token"
 
1
  import asyncio
2
  import logging
 
3
  from io import BytesIO
4
 
5
  from fastapi import Depends, HTTPException, UploadFile, status
6
  from fastapi.security import HTTPAuthorizationCredentials, HTTPBearer
7
+ from config import Config
8
 
9
  from .inferencer import analyze_text_with_sentences, classify_text
10
  from .preprocess import parse_docx, parse_pdf, parse_txt
 
33
  # Verify Bearer token from Authorization header
34
  async def verify_token(credentials: HTTPAuthorizationCredentials = Depends(security)):
35
  token = credentials.credentials
36
+ expected_token = Config.SECRET_TOKEN
37
  if token != expected_token:
38
  raise HTTPException(
39
  status_code=status.HTTP_403_FORBIDDEN, detail="Invalid or expired token"