petter2025 commited on
Commit
aa5baaf
·
verified ·
1 Parent(s): 1f75a1f

Update hf_demo.py

Browse files
Files changed (1) hide show
  1. hf_demo.py +24 -34
hf_demo.py CHANGED
@@ -1,5 +1,5 @@
1
- # COMPLETE FIXED hf_demo.py with Hugging Face Spaces compatibility
2
- # ARF 3.3.9 DEMO WITH PROPER GRADIO 6.0+ CONFIGURATION
3
 
4
  import gradio as gr
5
  import time
@@ -9,7 +9,9 @@ import uuid
9
  import subprocess
10
  import sys
11
  import importlib
12
- import os # Added for environment detection
 
 
13
  from datetime import datetime, timedelta
14
  from typing import Dict, List, Optional, Tuple, Any, Union
15
  import numpy as np
@@ -27,7 +29,6 @@ if is_huggingface_spaces():
27
  os.environ['GRADIO_ANALYTICS_ENABLED'] = 'False'
28
  os.environ['GRADIO_SERVER_NAME'] = '0.0.0.0'
29
  os.environ['GRADIO_SERVER_PORT'] = '7860'
30
- os.environ['GRADIO_SSR_MODE'] = 'False'
31
 
32
  # Import enhanced engines
33
  try:
@@ -361,17 +362,17 @@ demo_state = EnhancedDemoState(ARF_UNIFIED_STATUS)
361
 
362
  # ============== GRADIO INTERFACE ==============
363
  def create_enhanced_demo():
364
- """Create enhanced demo with fixed HTML rendering bugs and Hugging Face Spaces compatibility"""
365
 
366
  # Get unified status
367
  arf_display = ARF_UNIFIED_STATUS['display_text']
368
  arf_badge_class = ARF_UNIFIED_STATUS['badge_class']
369
 
370
- # CRITICAL FIX: Remove theme and css from Blocks constructor for Gradio 6.0+
371
- # These will be passed to launch() instead
372
  with gr.Blocks(
373
- title=f"ARF {ARF_UNIFIED_STATUS['version']} - Mathematical Sophistication"
374
- # REMOVED: theme and css parameters - they now go in launch()
 
375
  ) as demo:
376
 
377
  # ===== HEADER =====
@@ -975,29 +976,18 @@ if __name__ == "__main__":
975
  # Create the demo
976
  demo = create_enhanced_demo()
977
 
978
- # CRITICAL FIX: Move theme and css to launch() for Gradio 6.0+ compatibility
979
- # This ensures both Hugging Face Spaces and local development work correctly
 
 
 
 
 
 
 
 
980
 
981
- # Base launch configuration
982
- launch_kwargs = {
983
- 'server_name': "0.0.0.0",
984
- 'server_port': 7860,
985
- 'share': False, # Don't create share links in Spaces
986
- 'debug': False, # Disable debug mode in production
987
- 'ssr_mode': False, # Disable experimental SSR mode
988
- 'show_error': True, # Show errors for debugging
989
- 'prevent_thread_lock': is_huggingface_spaces(), # Prevent thread blocking in Spaces
990
- 'quiet': False, # Show full logs
991
- # Move theme and css here for Gradio 6.0+ compatibility
992
- 'theme': gr.themes.Soft(primary_hue="blue", secondary_hue="orange"),
993
- 'css': ENHANCED_CSS
994
- }
995
-
996
- # Add auth for local development if needed
997
- if not is_huggingface_spaces():
998
- # For local development, we can enable share links
999
- launch_kwargs['share'] = True
1000
- launch_kwargs['debug'] = True
1001
-
1002
- # Launch the demo
1003
- demo.launch(**launch_kwargs)
 
1
+ # COMPLETE FIXED hf_demo.py with Gradio 4.x for Hugging Face Spaces
2
+ # ARF 3.3.9 DEMO WITH PROPER HUGGING FACE SPACES COMPATIBILITY
3
 
4
  import gradio as gr
5
  import time
 
9
  import subprocess
10
  import sys
11
  import importlib
12
+ import os
13
+ import threading
14
+ import socket
15
  from datetime import datetime, timedelta
16
  from typing import Dict, List, Optional, Tuple, Any, Union
17
  import numpy as np
 
29
  os.environ['GRADIO_ANALYTICS_ENABLED'] = 'False'
30
  os.environ['GRADIO_SERVER_NAME'] = '0.0.0.0'
31
  os.environ['GRADIO_SERVER_PORT'] = '7860'
 
32
 
33
  # Import enhanced engines
34
  try:
 
362
 
363
  # ============== GRADIO INTERFACE ==============
364
  def create_enhanced_demo():
365
+ """Create enhanced demo with Gradio 4.x for Hugging Face Spaces compatibility"""
366
 
367
  # Get unified status
368
  arf_display = ARF_UNIFIED_STATUS['display_text']
369
  arf_badge_class = ARF_UNIFIED_STATUS['badge_class']
370
 
371
+ # GRADIO 4.x - theme and CSS go in Blocks constructor
 
372
  with gr.Blocks(
373
+ title=f"ARF {ARF_UNIFIED_STATUS['version']} - Mathematical Sophistication",
374
+ theme=gr.themes.Soft(primary_hue="blue", secondary_hue="orange"),
375
+ css=ENHANCED_CSS
376
  ) as demo:
377
 
378
  # ===== HEADER =====
 
976
  # Create the demo
977
  demo = create_enhanced_demo()
978
 
979
+ # GRADIO 4.x - Simple launch configuration (PROVEN TO WORK ON HUGGING FACE SPACES)
980
+ demo.launch(
981
+ server_name="0.0.0.0",
982
+ server_port=7860,
983
+ share=False,
984
+ debug=False,
985
+ prevent_thread_lock=True,
986
+ show_error=True,
987
+ quiet=False
988
+ )
989
 
990
+ # Keep the app alive
991
+ import time
992
+ while True:
993
+ time.sleep(1)