ark945 commited on
Commit ·
e215818
1
Parent(s): 38f139b
Fix timezone to UTC+8 and update deployment guide with HF push commands
Browse filesFiles changed (2)
- DEPLOYMENT_GUIDE.md+59-43
- app.py+7-4
123456789101112131415161718192021222324252627282930313233343536373839404142434445# 專案完成與部署指南我已成功建立 Streamlit 網站監控應用程式,並將程式碼推送至您的 GitHub:👉 [https://github.com/ark945/checkWeb](https://github.com/ark945/checkWeb)## 應用程式功能- **讀取清單**: 自動讀取 `urlList.txt`。- **狀態檢查**: 檢查網站 HTTP 狀態與回應時間。- **報告下載**: 支援將檢查結果下載為 CSV。## 🚀 如何部署到 Hugging Face Spaces請依照以下步驟將此應用程式發布到 Hugging Face:1. **登入 Hugging Face**- 前往 [huggingface.co](https://huggingface.co/) 並登入您的帳號。2. **建立新 Space**- 點擊右上角頭像旁的 **New Space**。- **Space Name**: 輸入 `checkWeb` (或您喜歡的名字)。- **License**: 選擇 `MIT` 或留空。- **Select the Space SDK**: 選擇 **Streamlit** (這很重要!)。- 點擊 **Create Space**。3. **上傳程式碼 (最簡單的方法)**Space 建立後,您有幾種方式上傳程式碼,建議使用「**Files**」頁面直接上傳:- 在您的 Space 頁面,點選上方的 **Files** 標籤。- 點選 **Add file** -> **Upload files**。- 將您電腦中 `d:\MyLab\checkWeb` 資料夾內的以下檔案拖曳上傳:- `app.py`- `requirements.txt`- `packages.txt` (新增:用於截圖功能)- `urlList.txt`- `README.md`- 在 "Commit changes" 訊息框輸入 "Add screenshot function",然後點擊 **Commit changes to main**。> **進階方法 (同步 GitHub)**:> 您也可以在 Space 的 **Settings** 中,找到 "Docker" 或相關設定來連結 GitHub Repository,這樣每次 GitHub 更新時 Space 也會自動更新。但直接上傳檔案通常最快。4. **等待建置**- 上傳後,Hugging Face 會自動開始安裝 `requirements.txt` 中的套件並啟動應用程式。- 等待幾分鐘,直到狀態顯示為 **Running**。5. **測試**- 您的應用程式現在應該可以在 Space 頁面上直接使用了!12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061# 網站狀態監控工具 - 部署指南## 應用程式功能- **狀態檢查**: 自動檢查網站 HTTP 狀態與回應時間- **網頁截圖**: 使用 Playwright 對每個網站進行截圖- **CSV 報告**: 匯出檢測結果為 CSV- **Word 報告**: 匯出包含截圖的完整 Word 報告## 🚀 部署到 Hugging Face Spaces### 方法一:透過 Git 直接推送(推薦)```bash# 1. 新增 Hugging Face 為遠端儲存庫(首次設定)git remote add hf https://huggingface.co/spaces/ark945/checkWeb# 2. 推送到 Hugging Facegit push hf main# 3. 如果推送被拒絕(歷史紀錄不同),使用強制推送git push hf main --force```### 方法二:同時推送到 GitHub 與 Hugging Face```bash# 推送到 GitHubgit push origin main# 推送到 Hugging Facegit push hf main```### 方法三:手動上傳1. 前往 [https://huggingface.co/spaces/ark945/checkWeb](https://huggingface.co/spaces/ark945/checkWeb)2. 點選上方的 **Files** 標籤3. 點選 **Add file** → **Upload files**4. 上傳以下檔案:- `app.py`- `requirements.txt`- `packages.txt`- `urlList.txt`- `README.md`- `.gitattributes`5. 點擊 **Commit changes to main**### 注意事項- `packages.txt` 和 `requirements.txt` 必須使用 **LF 換行格式**(不可使用 Windows 的 CRLF),否則 Linux 環境會讀取錯誤。專案中的 `.gitattributes` 已自動處理此問題。- Hugging Face 會根據 `README.md` 中的 `sdk_version` 自動安裝 Streamlit,因此 `requirements.txt` 中**不需要**包含 `streamlit`。## 🔧 常見問題| 問題 | 解決方式 ||------|----------|| 截圖中文亂碼 (□) | `packages.txt` 已包含 `fonts-noto-cjk` || 時間差 8 小時 | 程式已設定台灣時區 (UTC+8) || Build error: Unable to locate package | 確認 `.gitattributes` 已上傳,強制 LF 換行 || Runtime error: Could not resolve host | 點擊 Space 的「Restart this Space」重啟 || Failed to fetch module | 按 `Ctrl+Shift+R` 強制重新整理瀏覽器快取 |
123456795 unmodified lines10310410510610710810950 unmodified lines16016116216316416516644 unmodified lines211212213214215216217import streamlit as stimport requestsimport pandas as pdfrom datetime import datetimeimport asyncioimport osfrom playwright.async_api import async_playwright95 unmodified linesdoc = Document()doc.add_heading('網站狀態監控報告', 0)doc.add_paragraph(f'報告產生時間: {datetime.now().strftime("%Y-%m-%d %H:%M:%S")}')# Add summary tabletable = doc.add_table(rows=1, cols=4)50 unmodified lines# Check statuscheck_result = check_website(item['URL'])current_time = datetime.now().strftime("%Y-%m-%d %H:%M:%S")# Capture screenshotscreenshot_file = f"screenshots/{i}.png"44 unmodified linesst.download_button(label="下載 Word 完整報告 (含截圖)",data=docx_data,file_name=f"website_report_{datetime.now().strftime('%Y%m%d_%H%M%S')}.docx",mime="application/vnd.openxmlformats-officedocument.wordprocessingml.document",key='download-docx',use_container_width=True1234567891095 unmodified lines10610710810911011111250 unmodified lines16316416516616716816944 unmodified lines214215216217218219220import streamlit as stimport requestsimport pandas as pdfrom datetime import datetime, timezone, timedelta# 台灣時區 (UTC+8)TW_TZ = timezone(timedelta(hours=8))import asyncioimport osfrom playwright.async_api import async_playwright95 unmodified linesdoc = Document()doc.add_heading('網站狀態監控報告', 0)doc.add_paragraph(f'報告產生時間: {datetime.now(TW_TZ).strftime("%Y-%m-%d %H:%M:%S")}')# Add summary tabletable = doc.add_table(rows=1, cols=4)50 unmodified lines# Check statuscheck_result = check_website(item['URL'])current_time = datetime.now(TW_TZ).strftime("%Y-%m-%d %H:%M:%S")# Capture screenshotscreenshot_file = f"screenshots/{i}.png"44 unmodified linesst.download_button(label="下載 Word 完整報告 (含截圖)",data=docx_data,file_name=f"website_report_{datetime.now(TW_TZ).strftime('%Y%m%d_%H%M%S')}.docx",mime="application/vnd.openxmlformats-officedocument.wordprocessingml.document",key='download-docx',use_container_width=True
DEPLOYMENT_GUIDE.md+59-43
app.py+7-4