Spaces:
Sleeping
Sleeping
File size: 4,805 Bytes
fd77f04 |
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 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 |
#!/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)
|