C.W.K.
Stream
Lesson 03 of 04 · published

Streamlit, Docker, Static Spaces

~24 min · spaces, streamlit, docker

Level 0스카우트
0 XP0/50 lessons0/10 achievements
0/120 XP to next level120 XP to go0% complete

State 필요하면 Streamlit

Gradio 의 멘탈 모델은 “Python 함수 → UI”. Streamlit 의 모델은 “상호작용에 스크립트 top-to-bottom 재실행”. 멀티 페이지 대시보드 또는 persistent session state 필요한 앱엔 Streamlit 이 더 자연 — st.session_state 가 purpose-built.

다른 거 필요하면 Docker Space

FastAPI? Vue? non-standard Python? 커스텀 Nginx? GPU driver? Dockerfile 빌드, manifest 에 sdk: docker 선택. Spaces 가 컨테이너 빌드 + 실행. HF 컨테이너가 user 1000 (non-root) 실행; Dockerfile 이에 맞춰 디자인.

Static Spaces 는 HTML 무료 호스팅

모델 쇼케이스, 튜토리얼, 마케팅 페이지가 런타임 필요 없으면 sdk: static 셋, HTML/CSS/JS push. HF 가 너 다른 Spaces 와 같은 도메인에 서빙. 무료, 빠름, cold-start X.

Code

HF inference 콜 둘러싼 Streamlit 대시보드·python
import streamlit as st
from huggingface_hub import InferenceClient

st.title("Quick Llama Sandbox")

if "history" not in st.session_state:
    st.session_state.history = []

prompt = st.text_input("Prompt")
if st.button("Send") and prompt:
    client = InferenceClient(model="meta-llama/Llama-3.1-8B-Instruct", provider="hf-inference")
    out = client.chat_completion(messages=[{"role": "user", "content": prompt}], max_tokens=200)
    st.session_state.history.append((prompt, out.choices[0].message.content))

for u, a in st.session_state.history:
    st.markdown(f"**You:** {u}")
    st.markdown(f"**Llama:** {a}")
Docker Space — README front-matter·yaml
---
title: FastAPI Demo
sdk: docker
app_port: 7860
---
Docker Space 용 Dockerfile (FastAPI)·python
# Dockerfile
FROM python:3.11-slim
RUN useradd -m -u 1000 user
USER user
WORKDIR /home/user/app

COPY --chown=user requirements.txt .
RUN pip install --no-cache-dir -r requirements.txt

COPY --chown=user . .

# Spaces 디폴트 포트 7860 — manifest 의 app_port 로 override.
EXPOSE 7860
CMD ["uvicorn", "main:app", "--host", "0.0.0.0", "--port", "7860"]

External links

Exercise

다른 챗 모델 셋 side-by-side 비교 가능한 Streamlit Space 대시보드 빌드. 같은 대시보드를 FastAPI + tiny HTML 페이지의 Docker Space 로 빌드. 비교: deploy 시간, cold-start, 뭔가 깨졌을 때 디버그 ease.

Progress

Progress is local-only — sign in to sync across devices.
이 페이지에서 버그를 발견하셨거나 피드백이 있으세요?문제 신고

댓글 0

🔔 답글 알림 (로그인 필요)
로그인댓글을 남기려면 로그인해 주세요.

아직 댓글이 없어요. 첫 댓글을 남겨보세요.