Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -29,7 +29,6 @@ if api_available:
|
|
29 |
|
30 |
# --- 元素資料定義 ---
|
31 |
ELEMENTS_DATA = {
|
32 |
-
# 這裡省略了完整的元素資料,以節省空間,實際程式碼應包含所有元素
|
33 |
"H": {"name": "氫", "symbol": "H", "number": 1, "period": 1, "group": 1, "category": "nonmetal"},
|
34 |
"He": {"name": "氦", "symbol": "He", "number": 2, "period": 1, "group": 18, "category": "noble_gas"},
|
35 |
"Li": {"name": "鋰", "symbol": "Li", "number": 3, "period": 2, "group": 1, "category": "alkali_metal"},
|
@@ -139,7 +138,6 @@ def get_element_image(symbol):
|
|
139 |
return image_url
|
140 |
except requests.exceptions.RequestException as e:
|
141 |
print(f"獲取圖片時發生錯誤: {e}")
|
142 |
-
# 維持使用者指定的版本
|
143 |
return "https://dummyimage.com/400x400/2c3e50/ecf0f1.png&text=image+not+found"
|
144 |
|
145 |
def get_element_trivia(element_name):
|
@@ -158,7 +156,6 @@ def get_element_trivia(element_name):
|
|
158 |
"請讓內容兼具知識性與趣味性,排版清晰易讀,適合一般大眾閱讀。"
|
159 |
)
|
160 |
|
161 |
-
# 維持使用者指定的版本
|
162 |
response = client.models.generate_content(
|
163 |
model="gemini-2.0-flash-lite",
|
164 |
contents=prompt
|
@@ -269,7 +266,7 @@ def create_interface():
|
|
269 |
url.searchParams.set('__theme', 'dark');
|
270 |
window.location.href = url.href;
|
271 |
} else {
|
272 |
-
//
|
273 |
const observer = new MutationObserver((mutations, obs) => {
|
274 |
const table = document.getElementById('periodic-table-container');
|
275 |
if (table) {
|
@@ -347,7 +344,6 @@ def create_interface():
|
|
347 |
def process_element_selection(symbol):
|
348 |
if not symbol or symbol not in ELEMENTS_DATA:
|
349 |
return (
|
350 |
-
# 維持使用者指定的版本
|
351 |
"https://dummyimage.com/400x400/2c3e50/ecf0f1.png&text=invalid+choice",
|
352 |
"<div style='padding: 10px; text-align: center;'>請選擇一個有效的元素</div>",
|
353 |
"請從左側週期表中選擇一個有效的元素。"
|
|
|
29 |
|
30 |
# --- 元素資料定義 ---
|
31 |
ELEMENTS_DATA = {
|
|
|
32 |
"H": {"name": "氫", "symbol": "H", "number": 1, "period": 1, "group": 1, "category": "nonmetal"},
|
33 |
"He": {"name": "氦", "symbol": "He", "number": 2, "period": 1, "group": 18, "category": "noble_gas"},
|
34 |
"Li": {"name": "鋰", "symbol": "Li", "number": 3, "period": 2, "group": 1, "category": "alkali_metal"},
|
|
|
138 |
return image_url
|
139 |
except requests.exceptions.RequestException as e:
|
140 |
print(f"獲取圖片時發生錯誤: {e}")
|
|
|
141 |
return "https://dummyimage.com/400x400/2c3e50/ecf0f1.png&text=image+not+found"
|
142 |
|
143 |
def get_element_trivia(element_name):
|
|
|
156 |
"請讓內容兼具知識性與趣味性,排版清晰易讀,適合一般大眾閱讀。"
|
157 |
)
|
158 |
|
|
|
159 |
response = client.models.generate_content(
|
160 |
model="gemini-2.0-flash-lite",
|
161 |
contents=prompt
|
|
|
266 |
url.searchParams.set('__theme', 'dark');
|
267 |
window.location.href = url.href;
|
268 |
} else {
|
269 |
+
// 設定事件監聽
|
270 |
const observer = new MutationObserver((mutations, obs) => {
|
271 |
const table = document.getElementById('periodic-table-container');
|
272 |
if (table) {
|
|
|
344 |
def process_element_selection(symbol):
|
345 |
if not symbol or symbol not in ELEMENTS_DATA:
|
346 |
return (
|
|
|
347 |
"https://dummyimage.com/400x400/2c3e50/ecf0f1.png&text=invalid+choice",
|
348 |
"<div style='padding: 10px; text-align: center;'>請選擇一個有效的元素</div>",
|
349 |
"請從左側週期表中選擇一個有效的元素。"
|