所有匹配主题的 Gist streamlit

最后活跃于 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
最后活跃于 10 months ago
這段程式碼使用 Streamlit 建立一個 WebSocket 測試介面,當使用者按下按鈕時,會透過 WebSocket 用戶端向伺服器發送訊息,並顯示伺服器的回應。同時,它會在背景啟動 WebSocket 伺服器(如果尚未啟動),允許用戶端與其通訊,適用於即時通訊測試、開發 WebSocket 服務或簡單的雙向訊息傳遞應用。
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 / SQLite 與 Streamlit st.data_editor 整合

0 喜欢
0 派生
1 文件
最后活跃于 10 months ago
這段程式碼是一個使用 Streamlit 和 SQLite 的範例應用程式,透過 JOIN 查詢顯示客戶與訂單的關聯資料,並在介面中使用 st.data_editor 允許編輯訂單日期,按下更新按鈕後會將修改內容同步至資料庫。
1 import sqlite3
2 import pandas as pd
3 import streamlit as st
4 from datetime import datetime, date
5
6 def initialize_database(conn):
7 cursor = conn.cursor()
8
9 # 建立 Customers 資料表
10 cursor.execute('''

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