lightmate commited on
Commit
9b50d9f
Β·
verified Β·
1 Parent(s): 475efe5

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +19 -7
app.py CHANGED
@@ -44,6 +44,15 @@ def get_session_id():
44
  # Simplified trial management for HF Spaces
45
  trial_tracker = {}
46
 
 
 
 
 
 
 
 
 
 
47
  def get_trial_count() -> int:
48
  """Get current trial verification count."""
49
  session_id = get_session_id()
@@ -57,6 +66,9 @@ def increment_trial_count() -> int:
57
  trial_tracker[session_id] = new_count
58
  return new_count
59
 
 
 
 
60
  # DeBERTa API Functions
61
  async def call_deberta_api_async(evidence: str, claim: str, session_timeout: int = 30) -> dict:
62
  """Async call to DeBERTa FEVER API for fact verification."""
@@ -361,14 +373,14 @@ def verify_news_simple(input_text: str, progress=gr.Progress()) -> str:
361
  try:
362
  # Check trial limits for free users
363
  current_count = get_trial_count()
364
- if current_count >= 2:
365
- return """
366
  <div style="background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
367
  padding: 2rem; border-radius: 12px; color: white; text-align: center;
368
  box-shadow: 0 10px 25px rgba(0,0,0,0.1);">
369
  <h2 style="margin: 0 0 1rem 0; font-size: 1.5rem; color: white !important;">πŸ” Trial Limit Reached</h2>
370
  <p style="margin: 0 0 1.5rem 0; opacity: 0.9; color: white !important;">
371
- You've used your 2 free verifications! This is a demo version on HuggingFace Spaces.
372
  </p>
373
  <p style="margin: 0; font-size: 0.9rem; opacity: 0.8; color: white !important;">
374
  For unlimited access, deploy your own instance.
@@ -378,7 +390,7 @@ def verify_news_simple(input_text: str, progress=gr.Progress()) -> str:
378
 
379
  # Increment trial count
380
  new_count = increment_trial_count()
381
- remaining = 2 - new_count
382
 
383
  progress(0.05, desc="πŸ“ Processing input text...")
384
  time.sleep(2) # 2 sec for input processing
@@ -435,7 +447,7 @@ def verify_news_simple(input_text: str, progress=gr.Progress()) -> str:
435
  """
436
 
437
  return trial_info + main_result + deberta_html
438
-
439
  except Exception as e:
440
  print(f"ERROR: {e}")
441
  progress(1.0, desc="❌ Error occurred")
@@ -475,7 +487,7 @@ def create_interface():
475
  }
476
 
477
  /* Button styling - match header section color (#9775fa) */
478
- button[variant="primary"],
479
  .gr-button-primary,
480
  .gr-button[data-variant="primary"],
481
  input[type="submit"] {
@@ -614,7 +626,7 @@ def create_interface():
614
  <h2 style="margin: 0 0 1rem 0; font-size: 1.4rem; font-weight: 600; color: white !important;">Advanced News Verification System</h2>
615
  <div style="background: rgba(255,255,255,0.15); border-radius: 8px; padding: 1rem; margin: 1rem 0;">
616
  <h3 style="margin: 0 0 0.5rem 0; font-size: 1.2rem; font-weight: bold; color: white !important;">πŸš€ Free Demo Version</h3>
617
- <p style="margin: 0; opacity: 0.9; font-size: 1rem; color: white !important;">Try our news verification system with 2 free searches per session!</p>
618
  <p style="margin: 0.5rem 0 0 0; font-size: 0.9rem; opacity: 0.8; color: white !important;">Powered by DeBERTa AI + Evidence Search</p>
619
  </div>
620
  </div>
 
44
  # Simplified trial management for HF Spaces
45
  trial_tracker = {}
46
 
47
+ # Trial limit configuration (can be changed easily)
48
+ TRIAL_LIMIT = 5 # Increased from 2 to 5 for better demo experience
49
+
50
+ def clear_trial_cache():
51
+ """Clear all trial tracking data - useful for demos and testing."""
52
+ global trial_tracker
53
+ trial_tracker.clear()
54
+ print("βœ… Trial cache cleared - all users can start fresh!")
55
+
56
  def get_trial_count() -> int:
57
  """Get current trial verification count."""
58
  session_id = get_session_id()
 
66
  trial_tracker[session_id] = new_count
67
  return new_count
68
 
69
+ # Clear cache on startup to ensure fresh start
70
+ clear_trial_cache()
71
+
72
  # DeBERTa API Functions
73
  async def call_deberta_api_async(evidence: str, claim: str, session_timeout: int = 30) -> dict:
74
  """Async call to DeBERTa FEVER API for fact verification."""
 
373
  try:
374
  # Check trial limits for free users
375
  current_count = get_trial_count()
376
+ if current_count >= TRIAL_LIMIT:
377
+ return f"""
378
  <div style="background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
379
  padding: 2rem; border-radius: 12px; color: white; text-align: center;
380
  box-shadow: 0 10px 25px rgba(0,0,0,0.1);">
381
  <h2 style="margin: 0 0 1rem 0; font-size: 1.5rem; color: white !important;">πŸ” Trial Limit Reached</h2>
382
  <p style="margin: 0 0 1.5rem 0; opacity: 0.9; color: white !important;">
383
+ You've used your {TRIAL_LIMIT} free verifications! This is a demo version on HuggingFace Spaces.
384
  </p>
385
  <p style="margin: 0; font-size: 0.9rem; opacity: 0.8; color: white !important;">
386
  For unlimited access, deploy your own instance.
 
390
 
391
  # Increment trial count
392
  new_count = increment_trial_count()
393
+ remaining = TRIAL_LIMIT - new_count
394
 
395
  progress(0.05, desc="πŸ“ Processing input text...")
396
  time.sleep(2) # 2 sec for input processing
 
447
  """
448
 
449
  return trial_info + main_result + deberta_html
450
+
451
  except Exception as e:
452
  print(f"ERROR: {e}")
453
  progress(1.0, desc="❌ Error occurred")
 
487
  }
488
 
489
  /* Button styling - match header section color (#9775fa) */
490
+ button[variant="primary"],
491
  .gr-button-primary,
492
  .gr-button[data-variant="primary"],
493
  input[type="submit"] {
 
626
  <h2 style="margin: 0 0 1rem 0; font-size: 1.4rem; font-weight: 600; color: white !important;">Advanced News Verification System</h2>
627
  <div style="background: rgba(255,255,255,0.15); border-radius: 8px; padding: 1rem; margin: 1rem 0;">
628
  <h3 style="margin: 0 0 0.5rem 0; font-size: 1.2rem; font-weight: bold; color: white !important;">πŸš€ Free Demo Version</h3>
629
+ <p style="margin: 0; opacity: 0.9; font-size: 1rem; color: white !important;">Try our news verification system with 5 free searches per session!</p>
630
  <p style="margin: 0.5rem 0 0 0; font-size: 0.9rem; opacity: 0.8; color: white !important;">Powered by DeBERTa AI + Evidence Search</p>
631
  </div>
632
  </div>