w

webapp

Last active 5 hours ago flask metrics monitoring prometheus python webapp

使用 Flask 和 Prometheus 客戶端,快速設置基本的應用監控,輕鬆追蹤請求數量和延遲。

0 0 0 1
1 from flask import Flask, Response
2 from prometheus_client import Counter, Summary, generate_latest, CONTENT_TYPE_LATEST
3 import time
4
5 app = Flask(__name__)
6
7 # 自訂 metrics
8 REQUEST_COUNT = Counter('app_requests_total', 'Total number of requests')
9 REQUEST_LATENCY = Summary('app_request_latency_seconds', 'Request latency')

這是一個使用 Streamlit 實現的簡單計算器,支援中英文語系,提供加法和減法運算功能,適合快速數學計算。

0 0 0 1
1 import streamlit as st
2
3 # 多國語系字典
4 LANGUAGES = {
5 "zh": {
6 "title": "簡單計算器",
7 "instruction": "請輸入兩個數字,選擇運算方式:",
8 "num1": "數字 1",
9 "num2": "數字 2",
10 "operation": "選擇運算方式",

此範例展示如何在 Streamlit 應用中嵌入 HTML、CSS 和 JavaScript,允許自訂 UI 元素、樣式和互動功能,使 Web 應用更具靈活性和可視化效果。

0 0 0 2
1 import streamlit as st
2
3 st.title("嵌入 HTML 的範例")
4
5 html_code = """
6 <div style="border: 2px solid #4CAF50; padding: 10px; border-radius: 5px;">
7 <h2 style="color: #4CAF50;">這是一個 HTML 區塊</h2>
8 <p>你可以在這裡嵌入 HTML, CSS, 甚至 JavaScript。</p>
9 <button onclick="alert('Hello, Streamlit!')">點擊我</button>
10 </div>

此應用程式使用 streamlit_authenticator 進行使用者登入、登出及密碼重設,並支援 YAML 和 JSON 兩種格式作為驗證資料存儲。適用於需要帳戶管理的 Streamlit Web 應用,確保只有授權使用者可以存取內容。

0 0 0 1
1 import json
2 from abc import ABC, abstractmethod
3
4 import streamlit as st
5 import streamlit_authenticator as stauth
6 import yaml
7
8
9 # 策略介面
10 class DataHandlerStrategy(ABC):
Last active 5 hours ago bmi fitness health python pywebio webapp

此應用程式使用 PyWebIO 提供 Web 介面,讓使用者輸入身高和體重,並計算 BMI 指數。結果會顯示對應的 BMI 分類,例如正常、過重或肥胖等級。適用於健康管理與自我評估。

0 0 0 1
1 from pywebio import start_server
2 from pywebio.input import FLOAT, input # 引入 pywebio 模組中的 FLOAT 資料型態和 input 函數
3 from pywebio.output import put_text # 引入 pywebio 模組中的 put_text 函數
4
5 def bmi():
6 # 輸入身高和體重
7 height = input("您的身高(cm):", type=FLOAT)
8 weight = input("您的體重(kg):", type=FLOAT)
9
10 # 計算 BMI