timmy / 使用 Streamlit 與 Pydantic 建立使用者資訊展示
0 喜欢
0 派生
1 文件
最后活跃于 10 months ago
這段程式碼使用 pydantic 來定義使用者模型,並且透過 Streamlit 在網頁上顯示使用者資訊,同時 pretty_errors 提供美觀的錯誤訊息格式。
| 1 | from datetime import date |
| 2 | |
| 3 | import pretty_errors |
| 4 | import streamlit as st |
| 5 | from pydantic import BaseModel, Field |
| 6 | |
| 7 | |
| 8 | class User(BaseModel): |
| 9 | id: int |
| 10 | name: str |
timmy / 檢查 Python 版本是否受 Streamlit 支援
0 喜欢
0 派生
1 文件
最后活跃于 10 months ago
這段程式碼適合用於開發或部署 Streamlit 應用時,確保運行的 Python 版本符合 Streamlit 的支援範圍,避免因版本不符而導致問題。
| 1 | import sys |
| 2 | |
| 3 | class PythonVersionChecker: |
| 4 | def __init__(self, supported_versions): |
| 5 | self.supported_versions = supported_versions |
| 6 | |
| 7 | def get_current_version(self): |
| 8 | """取得當前的 Python 版本。""" |
| 9 | return sys.version_info[:2] |
timmy / 使用 Streamlit 建立 WebSocket 伺服器與客戶端
0 喜欢
0 派生
1 文件
最后活跃于 10 months ago
| 1 | import asyncio |
| 2 | import websockets |
| 3 | import streamlit as st |
| 4 | import threading |
| 5 | import socket |
| 6 | |
| 7 | # Function to check if a port is free |
| 8 | def is_port_free(port): |
| 9 | with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as s: |
| 10 | return s.connect_ex(('localhost', port)) != 0 |
timmy / 策略模式在資料管理中的應用
0 喜欢
0 派生
1 文件
最后活跃于 10 months ago
此範例展示策略模式在 YAML 和 JSON 資料處理中的應用,DataHandlerStrategy 定義通用的讀寫介面,並透過 YamlHandler 和 JsonHandler 來處理不同格式的資料。DataManager 負責管理資料存取,並可動態切換處理策略,提高靈活性與可維護性。
| 1 | import time |
| 2 | import yaml |
| 3 | import json |
| 4 | from abc import ABC, abstractmethod |
| 5 | import streamlit as st |
| 6 | |
| 7 | # 策略介面 |
| 8 | class DataHandlerStrategy(ABC): |
| 9 | @abstractmethod |
| 10 | def read_data(self, path): |
timmy / Streamlit 使用者驗證系統
0 喜欢
0 派生
1 文件
最后活跃于 10 months ago
| 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): |
timmy / 使用 Streamlit 建立 YAML 員工資料管理系統
0 喜欢
0 派生
2 文件
最后活跃于 10 months ago
此程式使用 Streamlit 讀取、編輯並儲存員工資料至 YAML 檔案,提供直覺化 UI 介面,並支援欄位過濾與年齡篩選,適用於企業資料管理。
| 1 | employees: |
| 2 | - Age: 34 |
| 3 | City: New York |
| 4 | Name: Alice |
| 5 | Occupation: Engineer |
| 6 | Salary: 70000 |
| 7 | - Age: 27 |
| 8 | City: Los Angeles |
| 9 | Name: Bob |
| 10 | Occupation: Doctor |
timmy / 使用 Streamlit 建立 YAML 編輯器
0 喜欢
0 派生
1 文件
最后活跃于 10 months ago
此程式使用 Streamlit 讓使用者讀取、編輯並儲存 YAML 文件,透過 pandas 轉換為表格格式,適用於設定檔管理與資料編輯工具。
| 1 | from io import StringIO |
| 2 | |
| 3 | import pandas as pd |
| 4 | import streamlit as st |
| 5 | import yaml |
| 6 | |
| 7 | |
| 8 | # 定義 YamlHandler 類 |
| 9 | class YamlHandler: |
| 10 | def __init__(self, file_path): |
timmy / 使用 Streamlit 建立 YAML 設定檔編輯器
0 喜欢
0 派生
2 文件
最后活跃于 10 months ago
此程式使用 Streamlit 讀取、編輯並存儲 YAML 設定檔,透過 pandas 轉換為表格格式,提供直覺化 UI 介面,適用於設定管理與資料修改。
| 1 | age: 30 |
| 2 | is_active: true |
| 3 | name: John Doe |
timmy / 使用 Streamlit 建立線上訂餐系統
0 喜欢
0 派生
1 文件
最后活跃于 10 months ago
這是一個使用 Streamlit 構建的訂餐系統,包含訂購人選擇、餐廳菜單顯示、主餐及加點品項的選擇與數量輸入,並計算和顯示訂單詳情與總價。
| 1 | from datetime import date |
| 2 | |
| 3 | import streamlit as st |
| 4 | |
| 5 | # 定義 Customer 類別 |
| 6 | class Customer: |
| 7 | def __init__(self, name, email, preferences): |
| 8 | self.name = name |
| 9 | self.email = email |
| 10 | self.preferences = preferences |