Spaces:
Sleeping
Sleeping
| #!/usr/bin/env python3 | |
| """ | |
| Environment Check Script for ConversAI | |
| Run this to diagnose configuration issues | |
| """ | |
| import os | |
| import sys | |
| def check_environment(): | |
| """Check environment variables and configuration""" | |
| print("="*70) | |
| print("ConversAI Environment Check") | |
| print("="*70) | |
| print() | |
| # Check Python version | |
| print(f"Python Version: {sys.version}") | |
| print() | |
| # Check environment variables | |
| print("Environment Variables:") | |
| print("-" * 70) | |
| env_vars = { | |
| "HF_TOKEN": "HuggingFace Token (auto in PUBLIC Spaces)", | |
| "HUGGINGFACE_API_KEY": "HuggingFace API Key (manual)", | |
| "OPENAI_API_KEY": "OpenAI API Key", | |
| "ANTHROPIC_API_KEY": "Anthropic API Key", | |
| "LLM_PROVIDER": "Explicit LLM Provider", | |
| "LLM_MODEL": "Custom Model Name", | |
| "SPACE_ID": "HuggingFace Space ID (if in Space)" | |
| } | |
| has_any_key = False | |
| for var, description in env_vars.items(): | |
| value = os.getenv(var) | |
| if value: | |
| has_any_key = True | |
| # Show first 10 chars for security | |
| preview = value[:10] + "..." if len(value) > 10 else value | |
| print(f"β {var:<25} SET ({preview})") | |
| else: | |
| print(f"β {var:<25} NOT SET") | |
| print() | |
| print("-" * 70) | |
| print() | |
| # Determine what will happen | |
| print("Configuration Status:") | |
| print("-" * 70) | |
| if not has_any_key: | |
| print("β NO CREDENTIALS FOUND") | |
| print() | |
| print("The app will NOT work without LLM credentials.") | |
| print() | |
| print("Solutions:") | |
| print("1. If on HuggingFace Spaces:") | |
| print(" β Make sure Space is PUBLIC (Settings β Visibility)") | |
| print(" β Or add HUGGINGFACE_API_KEY in Settings β Variables") | |
| print() | |
| print("2. If running locally:") | |
| print(" β Set OPENAI_API_KEY environment variable") | |
| print(" β Or set ANTHROPIC_API_KEY") | |
| print(" β Or set HUGGINGFACE_API_KEY") | |
| print() | |
| return False | |
| # Check which provider will be used | |
| provider = os.getenv("LLM_PROVIDER", "").lower() | |
| if provider == "openai" and os.getenv("OPENAI_API_KEY"): | |
| print("β Will use: OpenAI (explicit)") | |
| elif provider == "anthropic" and os.getenv("ANTHROPIC_API_KEY"): | |
| print("β Will use: Anthropic Claude (explicit)") | |
| elif provider == "huggingface" and (os.getenv("HUGGINGFACE_API_KEY") or os.getenv("HF_TOKEN")): | |
| print("β Will use: HuggingFace Inference API (explicit)") | |
| elif os.getenv("HF_TOKEN") or os.getenv("HUGGINGFACE_API_KEY"): | |
| print("β Will use: HuggingFace Inference API (auto-detected)") | |
| elif os.getenv("OPENAI_API_KEY"): | |
| print("β Will use: OpenAI (auto-detected)") | |
| elif os.getenv("ANTHROPIC_API_KEY"): | |
| print("β Will use: Anthropic Claude (auto-detected)") | |
| else: | |
| print("β οΈ Unknown configuration") | |
| print() | |
| # Check if in HuggingFace Spaces | |
| if os.getenv("SPACE_ID"): | |
| print(f"π Running in HuggingFace Space: {os.getenv('SPACE_ID')}") | |
| if not (os.getenv("HF_TOKEN") or os.getenv("HUGGINGFACE_API_KEY")): | |
| print("β οΈ WARNING: In HF Space but no HF token found!") | |
| print(" This Space might be PRIVATE. Consider:") | |
| print(" 1. Making it PUBLIC, or") | |
| print(" 2. Adding HUGGINGFACE_API_KEY manually") | |
| else: | |
| print("π Running locally (not in HuggingFace Space)") | |
| print() | |
| print("-" * 70) | |
| print() | |
| # Check imports | |
| print("Checking Python Dependencies:") | |
| print("-" * 70) | |
| dependencies = { | |
| "gradio": "Gradio UI framework", | |
| "requests": "HTTP library", | |
| "pandas": "Data processing (optional)" | |
| } | |
| all_imports_ok = True | |
| for module, description in dependencies.items(): | |
| try: | |
| __import__(module) | |
| print(f"β {module:<20} OK") | |
| except ImportError: | |
| print(f"β {module:<20} NOT INSTALLED") | |
| all_imports_ok = False | |
| print() | |
| if not all_imports_ok: | |
| print("β οΈ Some dependencies missing. Run:") | |
| print(" pip install -r requirements.txt") | |
| print() | |
| print("="*70) | |
| if has_any_key and all_imports_ok: | |
| print("β Environment looks good! You should be able to run the app.") | |
| print() | |
| print("Start the app with:") | |
| print(" python app.py") | |
| return True | |
| else: | |
| print("β Environment has issues. Fix the problems above.") | |
| return False | |
| if __name__ == "__main__": | |
| success = check_environment() | |
| sys.exit(0 if success else 1) | |