lightmate commited on
Commit
66b71d0
·
verified ·
1 Parent(s): 1987775

Upload app.py with huggingface_hub

Browse files
Files changed (1) hide show
  1. app.py +25 -2
app.py CHANGED
@@ -15,11 +15,23 @@ from components.verification_result import format_verification_results
15
  class SpacesSettings:
16
  def __init__(self):
17
  # For Spaces deployment, we'll use environment variables
18
- self.API_BASE_URL = os.getenv("API_BASE_URL", "https://your-backend-api.com")
 
 
19
  self.API_ENDPOINT = f"{self.API_BASE_URL}/api/verify"
20
  self.HEALTH_ENDPOINT = f"{self.API_BASE_URL}/api/health"
21
 
22
- settings = SpacesSettings()
 
 
 
 
 
 
 
 
 
 
23
 
24
  # Simple API client for Spaces
25
  class SimpleAPIClient:
@@ -91,6 +103,17 @@ def verify_news_with_trial_check(input_text: str, request: gr.Request) -> str:
91
  if not input_text.strip():
92
  return "Please enter some text or URL to verify"
93
 
 
 
 
 
 
 
 
 
 
 
 
94
  try:
95
  # Get session ID for trial tracking
96
  session_id = get_session_id(request)
 
15
  class SpacesSettings:
16
  def __init__(self):
17
  # For Spaces deployment, we'll use environment variables
18
+ self.API_BASE_URL = os.getenv("API_BASE_URL")
19
+ if not self.API_BASE_URL:
20
+ raise ValueError("API_BASE_URL environment variable is required")
21
  self.API_ENDPOINT = f"{self.API_BASE_URL}/api/verify"
22
  self.HEALTH_ENDPOINT = f"{self.API_BASE_URL}/api/health"
23
 
24
+ # Initialize settings with error handling
25
+ try:
26
+ settings = SpacesSettings()
27
+ except ValueError as e:
28
+ # Create a dummy settings object for graceful degradation
29
+ class DummySettings:
30
+ API_BASE_URL = None
31
+ API_ENDPOINT = None
32
+ HEALTH_ENDPOINT = None
33
+ settings = DummySettings()
34
+ print(f"Warning: {e}")
35
 
36
  # Simple API client for Spaces
37
  class SimpleAPIClient:
 
103
  if not input_text.strip():
104
  return "Please enter some text or URL to verify"
105
 
106
+ # Check if API_BASE_URL is configured
107
+ if not settings.API_BASE_URL:
108
+ return """
109
+ <div style="background: #f8d7da; border: 1px solid #f5c6cb; padding: 1rem; margin: 1rem 0; border-radius: 4px;">
110
+ <p style="margin: 0; color: #721c24; font-size: 0.9rem;">
111
+ ⚠️ <strong>Configuration Error:</strong> API_BASE_URL environment variable is not set.
112
+ Please configure it in the Space settings.
113
+ </p>
114
+ </div>
115
+ """
116
+
117
  try:
118
  # Get session ID for trial tracking
119
  session_id = get_session_id(request)