Spaces:
Sleeping
Sleeping
fix
Browse files- app.py +13 -17
- cities_data.py +10 -10
app.py
CHANGED
|
@@ -191,16 +191,10 @@ def generate_poster(
|
|
| 191 |
|
| 192 |
# Detect if we are selecting an entire province
|
| 193 |
is_whole_province = False
|
| 194 |
-
if selected_country == "中国":
|
| 195 |
-
|
| 196 |
-
|
| 197 |
-
|
| 198 |
-
from cities_data import _load_china_info
|
| 199 |
-
info = _load_china_info()
|
| 200 |
-
p_entry = info.get(str(p_adcode))
|
| 201 |
-
if p_entry and p_entry.get("childrenNum", 0) > 0:
|
| 202 |
-
if p_entry["children"][0].get("level") == "city":
|
| 203 |
-
is_whole_province = True
|
| 204 |
|
| 205 |
if not selected_location:
|
| 206 |
return None, "❌ 请选择城市或区县名称"
|
|
@@ -216,14 +210,14 @@ def generate_poster(
|
|
| 216 |
# but let's ensure it's at least 150km for a province.
|
| 217 |
if distance < 100000:
|
| 218 |
actual_distance = 200000 # 200km default for province
|
| 219 |
-
print(f"Whole province detected. Increasing distance to {actual_distance}m")
|
| 220 |
|
| 221 |
# Determine display names based on poster_lang
|
| 222 |
lang_code = "en" if poster_lang == "English" else "cn"
|
| 223 |
|
| 224 |
if selected_country == "中国" and lang_code == "cn":
|
| 225 |
if is_whole_province:
|
| 226 |
-
display_city =
|
| 227 |
display_country = "中国"
|
| 228 |
# Hierarchical logic for China (Chinese language)
|
| 229 |
elif district_dropdown and district_dropdown != city_dropdown:
|
|
@@ -400,6 +394,7 @@ def create_interface():
|
|
| 400 |
css="""
|
| 401 |
.header-title {
|
| 402 |
text-align: center;
|
|
|
|
| 403 |
font-size: 2em;
|
| 404 |
font-weight: bold;
|
| 405 |
margin-bottom: 0.5em;
|
|
@@ -431,11 +426,12 @@ def create_interface():
|
|
| 431 |
<div class="header-subtitle">选择任意城市,自定义主题风格,生成精美地图海报</div>
|
| 432 |
|
| 433 |
<div style="max-width: 800px; margin: 0 auto 20px auto; padding: 12px; background: #fff5f5; border: 1px solid #feb2b2; border-radius: 8px; text-align: left; font-size: 13px; line-height: 1.6; color: #c53030;">
|
| 434 |
-
<b>⚠️ 注意
|
| 435 |
-
• <b>特大城市</b>(如北京)
|
| 436 |
-
• <b>
|
| 437 |
-
• <b>
|
| 438 |
-
• <b>
|
|
|
|
| 439 |
</div>
|
| 440 |
""")
|
| 441 |
|
|
|
|
| 191 |
|
| 192 |
# Detect if we are selecting an entire province
|
| 193 |
is_whole_province = False
|
| 194 |
+
if selected_country == "中国" and selected_location:
|
| 195 |
+
if selected_location.endswith("_WHOLE"):
|
| 196 |
+
is_whole_province = True
|
| 197 |
+
selected_location = selected_location.replace("_WHOLE", "")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 198 |
|
| 199 |
if not selected_location:
|
| 200 |
return None, "❌ 请选择城市或区县名称"
|
|
|
|
| 210 |
# but let's ensure it's at least 150km for a province.
|
| 211 |
if distance < 100000:
|
| 212 |
actual_distance = 200000 # 200km default for province
|
| 213 |
+
print(f"Whole province detected ({selected_location}). Increasing distance to {actual_distance}m")
|
| 214 |
|
| 215 |
# Determine display names based on poster_lang
|
| 216 |
lang_code = "en" if poster_lang == "English" else "cn"
|
| 217 |
|
| 218 |
if selected_country == "中国" and lang_code == "cn":
|
| 219 |
if is_whole_province:
|
| 220 |
+
display_city = selected_location
|
| 221 |
display_country = "中国"
|
| 222 |
# Hierarchical logic for China (Chinese language)
|
| 223 |
elif district_dropdown and district_dropdown != city_dropdown:
|
|
|
|
| 394 |
css="""
|
| 395 |
.header-title {
|
| 396 |
text-align: center;
|
| 397 |
+
color: #666;
|
| 398 |
font-size: 2em;
|
| 399 |
font-weight: bold;
|
| 400 |
margin-bottom: 0.5em;
|
|
|
|
| 426 |
<div class="header-subtitle">选择任意城市,自定义主题风格,生成精美地图海报</div>
|
| 427 |
|
| 428 |
<div style="max-width: 800px; margin: 0 auto 20px auto; padding: 12px; background: #fff5f5; border: 1px solid #feb2b2; border-radius: 8px; text-align: left; font-size: 13px; line-height: 1.6; color: #c53030;">
|
| 429 |
+
<b>⚠️ 注意!</b><br>
|
| 430 |
+
• <b>特大城市</b>(如北京): 当城市面积过大时,中心定位可能不准。<br>
|
| 431 |
+
• <b>地点中英文不完善</b> : 由于地点中英文翻译数据量过大,未能显示完善<br>
|
| 432 |
+
• <b>小城市</b> : 由于 OpenStreetMap 数据缺失,部分图层(如公园/水域)可能无法显示。<br>
|
| 433 |
+
• <b>生成速度</b> : 国外地点使用国外服务器数据且渲染逻辑较基础,下载和生成速度可能较慢。<br>
|
| 434 |
+
• <b>数据来源</b> : © OpenStreetMap contributors
|
| 435 |
</div>
|
| 436 |
""")
|
| 437 |
|
cities_data.py
CHANGED
|
@@ -1157,22 +1157,22 @@ def get_cities(country_name, province_name, lang="en"):
|
|
| 1157 |
if p_entry:
|
| 1158 |
choices = []
|
| 1159 |
|
| 1160 |
-
# Add "Whole Province" option
|
| 1161 |
whole_province_display = "整个省" if lang == "cn" else "Whole Province"
|
| 1162 |
-
choices.append((whole_province_display, province_name))
|
| 1163 |
|
| 1164 |
-
|
| 1165 |
-
name = c["name"]
|
| 1166 |
-
display = translate(name, lang)
|
| 1167 |
-
choices.append((display, name))
|
| 1168 |
-
# Add the province itself if it's a municipality?
|
| 1169 |
-
# info.json treats municipalities as provinces with districts as children.
|
| 1170 |
-
# If children level is 'district', then the 'cities' list should be just [province_name]
|
| 1171 |
if (
|
| 1172 |
p_entry.get("children")
|
| 1173 |
and p_entry["children"][0].get("level") == "district"
|
| 1174 |
):
|
| 1175 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1176 |
|
| 1177 |
# Keep "Whole Province" at top, then sorted cities
|
| 1178 |
return [choices[0]] + sorted(choices[1:], key=lambda x: x[0])
|
|
|
|
| 1157 |
if p_entry:
|
| 1158 |
choices = []
|
| 1159 |
|
| 1160 |
+
# Add "Whole Province" option with a unique marker in the value
|
| 1161 |
whole_province_display = "整个省" if lang == "cn" else "Whole Province"
|
| 1162 |
+
choices.append((whole_province_display, province_name + "_WHOLE"))
|
| 1163 |
|
| 1164 |
+
# For municipalities, return [Whole Province, Municipality Name]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1165 |
if (
|
| 1166 |
p_entry.get("children")
|
| 1167 |
and p_entry["children"][0].get("level") == "district"
|
| 1168 |
):
|
| 1169 |
+
choices.append((translate(province_name, lang), province_name))
|
| 1170 |
+
return choices
|
| 1171 |
+
|
| 1172 |
+
for c in p_entry.get("children", []):
|
| 1173 |
+
name = c["name"]
|
| 1174 |
+
display = translate(name, lang)
|
| 1175 |
+
choices.append((display, name))
|
| 1176 |
|
| 1177 |
# Keep "Whole Province" at top, then sorted cities
|
| 1178 |
return [choices[0]] + sorted(choices[1:], key=lambda x: x[0])
|