file_content_viewer.py
· 412 B · Python
Неформатований
import streamlit as st
# 標題
st.title("文件內容查看器")
# 文件上傳
uploaded_file = st.file_uploader("請上傳文字或 Markdown 文件", type=["txt", "md"])
# 如果有文件被上傳
if uploaded_file is not None:
# 讀取文件內容
content = uploaded_file.read().decode("utf-8")
# 顯示文件內容
st.subheader(f"文件內容 ({uploaded_file.name})")
st.write(content)
| 1 | import streamlit as st |
| 2 | |
| 3 | # 標題 |
| 4 | st.title("文件內容查看器") |
| 5 | |
| 6 | # 文件上傳 |
| 7 | uploaded_file = st.file_uploader("請上傳文字或 Markdown 文件", type=["txt", "md"]) |
| 8 | |
| 9 | # 如果有文件被上傳 |
| 10 | if uploaded_file is not None: |
| 11 | # 讀取文件內容 |
| 12 | content = uploaded_file.read().decode("utf-8") |
| 13 | |
| 14 | # 顯示文件內容 |
| 15 | st.subheader(f"文件內容 ({uploaded_file.name})") |
| 16 | st.write(content) |