Spaces:
Running
Running
""" | |
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 | |
) | |