File size: 3,503 Bytes
a885b4f
ec92724
a885b4f
 
ec92724
a885b4f
 
ec92724
a885b4f
 
ec92724
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
aff60ee
 
 
 
 
 
 
 
 
 
 
 
ec92724
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
a885b4f
 
ec92724
a885b4f
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
"""
Hugging Face Spaces entry point for Fitness AI Assistant
"""
import sys
import os
from pathlib import Path

# Add the necessary paths
current_dir = Path(__file__).parent

# Add shared library to path
shared_path = current_dir / "shared" / "src"
if str(shared_path) not in sys.path:
    sys.path.insert(0, str(shared_path))

# Add gradio app to path  
gradio_app_path = current_dir / "apps" / "gradio-app" / "src"
if str(gradio_app_path) not in sys.path:
    sys.path.insert(0, str(gradio_app_path))

# Add fitness_agent to path
fitness_agent_path = current_dir / "fitness_agent"
if str(fitness_agent_path) not in sys.path:
    sys.path.insert(0, str(fitness_agent_path))

print("πŸš€ Starting Fitness AI Assistant...")
print(f"πŸ“‚ Working directory: {current_dir}")
print(f"πŸ” Python paths added:")
print(f"   - {shared_path}")
print(f"   - {gradio_app_path}")
print(f"   - {fitness_agent_path}")

try:
    print("πŸ“¦ Testing core imports...")
    import gradio as gr
    print("βœ“ Gradio imported successfully")
    
    # Try to import our modules step by step
    print("πŸ“¦ Testing fitness_core imports...")
    from fitness_core import setup_logging, Config, get_logger
    print("βœ“ fitness_core base imports successful")
    
    print("πŸ“¦ Testing fitness_gradio imports...")
    try:
        import scipy
        print("βœ“ scipy imported successfully")
    except ImportError as e:
        print(f"⚠️ scipy not available - audio processing will be limited: {e}")
    
    try:
        import groq
        print("βœ“ groq imported successfully")
    except ImportError as e:
        print(f"⚠️ groq not available - voice transcription will be limited: {e}")
    
    from fitness_gradio.ui import create_fitness_app
    print("βœ“ fitness_gradio imports successful")
    
    # Configure logging
    setup_logging(level=Config.LOG_LEVEL, log_file=Config.LOG_FILE)
    logger = get_logger(__name__)
    
    print("🎨 Creating Gradio app...")
    app = create_fitness_app()
    print("βœ… Successfully created full fitness app!")
    
except Exception as e:
    print(f"⚠️  Import error: {e}")
    print("πŸ”„ Creating fallback Gradio interface...")
    
    import gradio as gr
    
    def respond(message, history):
        return (f"πŸ‹οΈ Hello! I'm the Fitness AI Assistant. I'm currently in fallback mode due to missing dependencies.\n\n"
                f"You said: {message}\n\n"
                f"Please ensure all required dependencies are installed:\n"
                f"- openai-agents[litellm]\n"
                f"- python-dotenv\n"
                f"- pydantic\n\n"
                f"Once properly configured, I can help with:\n"
                f"- Fitness program design\n"
                f"- Nutrition advice\n"
                f"- Workout planning\n"
                f"- Health and wellness guidance")
    
    app = gr.ChatInterface(
        respond,
        title="πŸ‹οΈ Fitness AI Assistant",
        description="Your personal AI-powered fitness and nutrition coach (Fallback Mode)",
        examples=[
            "Create a beginner workout plan",
            "What should I eat after a workout?",
            "How many calories should I eat per day?",
            "Design a 30-day fitness challenge"
        ]
    )
    print("βœ… Created fallback interface")

if __name__ == "__main__":
    print("πŸš€ Launching Fitness AI Assistant...")
    app.launch(
        server_name="0.0.0.0",
        server_port=7860,
        share=False
    )