Spaces:
Sleeping
Sleeping
official.ghost.logic
commited on
Commit
·
0935d82
1
Parent(s):
ed1e0bc
Fix image generator to read API keys from environment
Browse files- Read OPENAI_API_KEY and HUGGINGFACE_API_KEY directly from env
- Support both HUGGINGFACE_API_KEY and HF_TOKEN
- Change error to warning (don't fail app startup)
- Add debug logging for image gen keys
- Image generation now optional if no keys provided
- src/utils/image_generator.py +11 -6
src/utils/image_generator.py
CHANGED
|
@@ -95,8 +95,9 @@ class ImageGenerator:
|
|
| 95 |
|
| 96 |
def __init__(self):
|
| 97 |
"""Initialize image generator with available providers"""
|
| 98 |
-
|
| 99 |
-
self.
|
|
|
|
| 100 |
|
| 101 |
self.output_dir = Path("data/portraits")
|
| 102 |
self.output_dir.mkdir(parents=True, exist_ok=True)
|
|
@@ -108,11 +109,15 @@ class ImageGenerator:
|
|
| 108 |
self.has_openai = bool(self.openai_api_key)
|
| 109 |
self.has_hf = bool(self.hf_api_key)
|
| 110 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 111 |
if not self.has_openai and not self.has_hf:
|
| 112 |
-
|
| 113 |
-
|
| 114 |
-
|
| 115 |
-
)
|
| 116 |
|
| 117 |
def generate_character_portrait(
|
| 118 |
self,
|
|
|
|
| 95 |
|
| 96 |
def __init__(self):
|
| 97 |
"""Initialize image generator with available providers"""
|
| 98 |
+
# Read API keys directly from environment
|
| 99 |
+
self.openai_api_key = os.getenv("OPENAI_API_KEY")
|
| 100 |
+
self.hf_api_key = os.getenv("HUGGINGFACE_API_KEY") or os.getenv("HF_TOKEN")
|
| 101 |
|
| 102 |
self.output_dir = Path("data/portraits")
|
| 103 |
self.output_dir.mkdir(parents=True, exist_ok=True)
|
|
|
|
| 109 |
self.has_openai = bool(self.openai_api_key)
|
| 110 |
self.has_hf = bool(self.hf_api_key)
|
| 111 |
|
| 112 |
+
if self.openai_api_key:
|
| 113 |
+
print(f"✅ OpenAI key found for image generation (key: {self.openai_api_key[:10]}...)")
|
| 114 |
+
if self.hf_api_key:
|
| 115 |
+
print(f"✅ HuggingFace key found for image generation (key: {self.hf_api_key[:10]}...)")
|
| 116 |
+
|
| 117 |
if not self.has_openai and not self.has_hf:
|
| 118 |
+
print("⚠️ Warning: No image generation API keys found")
|
| 119 |
+
print(" Image generation will not be available")
|
| 120 |
+
print(" Add OPENAI_API_KEY or HUGGINGFACE_API_KEY to HF Spaces Secrets")
|
|
|
|
| 121 |
|
| 122 |
def generate_character_portrait(
|
| 123 |
self,
|