Skip to content

Commit f9cd98a

Browse files
committed
Add random Hugging Face Space configuration to environment initialization
- Introduced `_get_random_hf_space_config` function to generate random emoji and color values for Hugging Face Spaces. - Updated `_create_template_replacements` to include placeholders for the new configuration values. - Modified `README.md` template to use dynamic placeholders for emoji and color settings.
1 parent e2b20e2 commit f9cd98a

File tree

2 files changed

+45
-3
lines changed

2 files changed

+45
-3
lines changed

src/openenv_cli/commands/init.py

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
from __future__ import annotations
44

55
import os
6+
import random
67
import shutil
78
from pathlib import Path
89
from typing import Annotated, Dict, List, Tuple
@@ -70,6 +71,39 @@ def _validate_env_name(name: str) -> str:
7071
return name
7172

7273

74+
def _get_random_hf_space_config() -> Dict[str, str]:
75+
"""
76+
Get random Hugging Face Space configuration values.
77+
78+
Returns:
79+
Dictionary with 'emoji', 'colorFrom', and 'colorTo' keys
80+
"""
81+
# Valid emojis (emoji-only characters)
82+
emojis = [
83+
"🎮", "🎯", "🚀", "🌟", "🎨", "🎪", "🎭", "🎬", "🎤", "🎧",
84+
"🎵", "🎶", "🎸", "🎹", "🥁", "🎺", "🎻", "🎼", "🎯", "🎲",
85+
"🎳", "🎰", "🎴", "🃏", "🀄", "🎴", "🎨", "🖼️", "🎬", "🎭",
86+
"🎪", "🎤", "🎧", "🎵", "🎶", "🎸", "🎹", "🎺", "🎻", "🥁",
87+
"🎯", "🎲", "🎳", "🎰", "🏀", "⚽", "🏈", "⚾", "🎾", "🏐",
88+
"🏉", "🎱", "🏓", "🏸", "🥅", "🏒", "🏑", "🏏", "⛳", "🏹",
89+
"🎣", "🥊", "🥋", "🎽", "🏅", "🎖️", "🏆", "🥇", "🥈", "🥉",
90+
"🔊", "🔉", "🔈", "🔇", "📢", "📣", "📯", "🔔", "🔕", "📻",
91+
"📡", "💻", "🖥️", "🖨️", "⌨️", "🖱️", "🖲️", "🕹️", "🗜️", "💾",
92+
"💿", "📀", "📼", "📷", "📸", "📹", "🎥", "📽️", "🎞️", "📞",
93+
"☎️", "📟", "📠", "📺", "📻", "🎙️", "🎚️", "🎛️", "⏱️", "⏲️",
94+
"⏰", "🕰️", "⌚", "📱", "📲", "💻", "⌨️", "🖥️", "🖨️", "🖱️",
95+
]
96+
97+
# Valid colors from HF Spaces config reference
98+
colors = ["red", "yellow", "green", "blue", "indigo", "purple", "pink", "gray"]
99+
100+
return {
101+
"emoji": random.choice(emojis),
102+
"colorFrom": random.choice(colors),
103+
"colorTo": random.choice(colors),
104+
}
105+
106+
73107
def _create_template_replacements(env_name: str) -> Dict[str, str]:
74108
"""
75109
Create comprehensive template replacement dictionary.
@@ -84,6 +118,9 @@ def _create_template_replacements(env_name: str) -> Dict[str, str]:
84118
env_camel = _snake_to_camel(env_name)
85119
env_title = _snake_to_title(env_name)
86120

121+
# Get random HF Space config values
122+
hf_config = _get_random_hf_space_config()
123+
87124
# Source names (echo_env)
88125
echo_env = "echo_env"
89126
echo_prefix = "Echo" # Prefix for echo_env classes
@@ -102,6 +139,11 @@ def _create_template_replacements(env_name: str) -> Dict[str, str]:
102139
"__ENV_TITLE_NAME__": env_title,
103140
"__ENV_CAMEL_NAME__": env_camel,
104141

142+
# Hugging Face Space config placeholders
143+
"__HF_EMOJI__": hf_config["emoji"],
144+
"__HF_COLOR_FROM__": hf_config["colorFrom"],
145+
"__HF_COLOR_TO__": hf_config["colorTo"],
146+
105147
# Module/file path replacements (snake_case)
106148
echo_env: env_name,
107149
f"{echo_env}_environment": f"{env_name}_environment",

src/openenv_cli/templates/openenv_env/README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
---
22
title: __ENV_TITLE_NAME__ Environment Server
3-
emoji: 🔊
4-
colorFrom: red
5-
colorTo: yellow
3+
emoji: __HF_EMOJI__
4+
colorFrom: __HF_COLOR_FROM__
5+
colorTo: __HF_COLOR_TO__
66
sdk: docker
77
pinned: false
88
app_port: 8000

0 commit comments

Comments
 (0)