🔍 DGaze
Advanced News Verification System
Free Trial: 2 verifications • Deploy your own for unlimited access
""" DGaze - Simplified Gradio App for Hugging Face Spaces """ import os import gradio as gr import requests import time import uuid # Import our modular components from components.verification_result import format_verification_results # Simple configuration for Spaces class SpacesSettings: def __init__(self): # For Spaces deployment, we'll use environment variables self.API_BASE_URL = os.getenv("API_BASE_URL") if not self.API_BASE_URL: raise ValueError("API_BASE_URL environment variable is required") self.API_ENDPOINT = f"{self.API_BASE_URL}/api/verify" self.HEALTH_ENDPOINT = f"{self.API_BASE_URL}/api/health" # Initialize settings with error handling try: settings = SpacesSettings() except ValueError as e: # Create a dummy settings object for graceful degradation class DummySettings: API_BASE_URL = None API_ENDPOINT = None HEALTH_ENDPOINT = None settings = DummySettings() print(f"Warning: {e}") # Simple API client for Spaces class SimpleAPIClient: def __init__(self): self.base_url = settings.API_BASE_URL self.verify_endpoint = settings.API_ENDPOINT self.health_endpoint = settings.HEALTH_ENDPOINT def verify_news(self, text: str) -> dict: """Verify news using the backend API.""" try: payload = {"text": text} response = requests.post( self.verify_endpoint, json=payload, timeout=30, headers={"Content-Type": "application/json"} ) response.raise_for_status() return response.json() except requests.exceptions.RequestException as e: raise Exception(f"API request failed: {str(e)}") except Exception as e: raise Exception(f"Verification failed: {str(e)}") api_client = SimpleAPIClient() # Free trial management for Spaces trial_tracker = {} session_timestamps = {} def get_session_id(request) -> str: """Get session ID from Gradio request.""" # For Spaces, we'll use a simpler session tracking if hasattr(request, 'headers'): # Try to get a unique identifier from headers session_id = request.headers.get('x-session-id', f"trial_{uuid.uuid4().hex[:12]}") else: session_id = f"trial_{uuid.uuid4().hex[:12]}" return session_id def cleanup_old_sessions(): """Clean up sessions older than 24 hours.""" current_time = time.time() old_sessions = [] for session_id, timestamp in session_timestamps.items(): if current_time - timestamp > 86400: # 24 hours old_sessions.append(session_id) for session_id in old_sessions: trial_tracker.pop(session_id, None) session_timestamps.pop(session_id, None) def get_trial_count(session_id: str) -> int: """Get current trial verification count.""" cleanup_old_sessions() return trial_tracker.get(session_id, 0) def increment_trial_count(session_id: str) -> int: """Increment and return trial verification count.""" current_count = trial_tracker.get(session_id, 0) new_count = current_count + 1 trial_tracker[session_id] = new_count session_timestamps[session_id] = time.time() return new_count def verify_news_with_trial_check(input_text: str, request: gr.Request) -> str: """Verification function with free trial tracking for Spaces.""" if not input_text.strip(): return "Please enter some text or URL to verify" # Check if API_BASE_URL is configured if not settings.API_BASE_URL: return """
⚠️ Configuration Error: API_BASE_URL environment variable is not set. Please configure it in the Space settings.
You've used your 2 free verifications! To continue using DGaze:
Thank you for trying DGaze!
⚡ Free Trial: {remaining} verification{'s' if remaining != 1 else ''} remaining {' • Deploy your own instance for unlimited access!' if remaining > 0 else ''}
Advanced News Verification System
Free Trial: 2 verifications • Deploy your own for unlimited access