Spaces:
Sleeping
Sleeping
Create _config.py
Browse files- _config.py +52 -0
_config.py
ADDED
|
@@ -0,0 +1,52 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import os
|
| 2 |
+
import logging
|
| 3 |
+
from typing import Optional
|
| 4 |
+
|
| 5 |
+
# Third-party imports
|
| 6 |
+
try:
|
| 7 |
+
from google import genai
|
| 8 |
+
except ImportError:
|
| 9 |
+
# We allow this to fail here, the app.py main will catch it.
|
| 10 |
+
genai = None
|
| 11 |
+
|
| 12 |
+
try:
|
| 13 |
+
from transformers import pipeline
|
| 14 |
+
except ImportError:
|
| 15 |
+
pipeline = None
|
| 16 |
+
|
| 17 |
+
logger = logging.getLogger("fact_checker_config")
|
| 18 |
+
|
| 19 |
+
# --- CONFIGURATION FROM ENVIRONMENT ---
|
| 20 |
+
GEMINI_API_KEY = os.getenv("GEMINI_API_KEY")
|
| 21 |
+
SERPAPI_KEY = os.getenv("SERPAPI_KEY")
|
| 22 |
+
SAFE_BROWSING_KEY = os.getenv("SAFE_BROWSING_KEY")
|
| 23 |
+
VIRUSTOTAL_KEY = os.getenv("VIRUSTOTAL_KEY")
|
| 24 |
+
GENAI_MODEL = os.getenv("GENAI_MODEL", "gemini-2.5-flash")
|
| 25 |
+
HF_ZERO_SHOT_MODEL = os.getenv("HF_ZERO_SHOT", "facebook/bart-large-mnli")
|
| 26 |
+
|
| 27 |
+
# Constants
|
| 28 |
+
CANDIDATE_LABELS = ["True", "False", "Misleading", "Unclear", "Opinionated", "Unsupported"]
|
| 29 |
+
MAX_BYTES = 6 * 1024 * 1024 # 6MB for image download
|
| 30 |
+
ALLOWED_CONTENT_PREFIXES = ("image/",)
|
| 31 |
+
SOURCE_TRUST = {
|
| 32 |
+
"reuters.com": 0.95, "apnews.com": 0.95, "bbc.com": 0.93, "theguardian.com": 0.9,
|
| 33 |
+
"nytimes.com": 0.9, "washingtonpost.com": 0.9,
|
| 34 |
+
}
|
| 35 |
+
|
| 36 |
+
# --- CLIENT INITIALIZATION ---
|
| 37 |
+
GEMINI_CLIENT: Optional[genai.Client] = None
|
| 38 |
+
ZERO_SHOT_CLASSIFIER: Optional[pipeline] = None
|
| 39 |
+
|
| 40 |
+
if GEMINI_API_KEY and genai:
|
| 41 |
+
try:
|
| 42 |
+
GEMINI_CLIENT = genai.Client(api_key=GEMINI_API_KEY)
|
| 43 |
+
logger.info("Gemini client initialized.")
|
| 44 |
+
except Exception as e:
|
| 45 |
+
logger.error(f"Failed to initialize Gemini client: {e}")
|
| 46 |
+
|
| 47 |
+
if pipeline:
|
| 48 |
+
try:
|
| 49 |
+
ZERO_SHOT_CLASSIFIER = pipeline("zero-shot-classification", model=HF_ZERO_SHOT_MODEL)
|
| 50 |
+
logger.info(f"Hugging Face zero-shot pipeline loaded: {HF_ZERO_SHOT_MODEL}")
|
| 51 |
+
except Exception as e:
|
| 52 |
+
logger.warning(f"Hugging Face pipeline initialization failed: {e}")
|