Spaces:
Sleeping
Sleeping
File size: 901 Bytes
8a78aa6 96702a6 8a78aa6 96702a6 8a78aa6 96702a6 8a78aa6 96702a6 8a78aa6 96702a6 8a78aa6 96702a6 8a78aa6 96702a6 8a78aa6 96702a6 8a78aa6 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
from typing import List, Optional
from pydantic import BaseModel, BaseSettings, SecretStr
import streamlit as st
# Slide 3: Basic Model
class User(BaseModel):
id: int
name: str = "Jane Doe"
data = {"id": 19, "name": "Fanilo", "age": 179}
user = User(**data)
st.write(user)
data = {"id": "Fanilo", "name": 42}
user = User(**data)
#st.write(user)
# Slide 4: Hierarchical Model
class Address(BaseModel):
city: str
street: Optional[str]
class User(BaseModel):
id: int
name: str
addresses: List[Address]
data = {
"id": 42,
"name": "Fanilo",
"addresses": [{"city": "Paris"}, {"city": "Tokyo", "street": "こんにちは"}],
}
user = User(**data)
st.success(user.addresses[1].street)
# Slide 7: Secrets
class Settings(BaseSettings):
auth_key: SecretStr
api_key: str
class Config:
env_file = "settings.env"
st.write(Settings().dict()) |