From c081ccb7aba9f6931b313390211e2a50b5ff683a Mon Sep 17 00:00:00 2001 From: teshima shinnosuke <5123033z@g.hit-u.ac.jp> Date: Wed, 30 Apr 2025 01:24:38 +0900 Subject: [PATCH 1/3] =?UTF-8?q?UI=E6=94=B9=E8=89=AF:=20=E3=82=B5=E3=82=A4?= =?UTF-8?q?=E3=83=89=E3=83=90=E3=83=BC=E3=81=A7=E3=83=9A=E3=83=BC=E3=82=B8?= =?UTF-8?q?=E5=88=87=E3=82=8A=E6=9B=BF=E3=81=88=E3=81=A7=E3=81=8D=E3=82=8B?= =?UTF-8?q?=E3=82=88=E3=81=86=E3=81=AB=E5=A4=89=E6=9B=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- day1/.env_template | 2 - day1/01_streamlit_UI/app.py | 204 +++++++++--------- day1/01_streamlit_UI/app_1.py | 78 +++++++ ...27\343\203\255\343\203\274\343\203\211.py" | 0 ...44\343\202\242\343\202\246\343\203\210.py" | 17 ++ .../\345\237\272\346\234\254UI.py" | 18 ++ day1/02_streamlit_app/lecture-ai-engineering | 1 + 7 files changed, 221 insertions(+), 99 deletions(-) delete mode 100644 day1/.env_template create mode 100644 day1/01_streamlit_UI/app_1.py create mode 100644 "day1/01_streamlit_UI/\343\203\225\343\202\241\343\202\244\343\203\253\343\202\242\343\203\203\343\203\227\343\203\255\343\203\274\343\203\211.py" create mode 100644 "day1/01_streamlit_UI/\343\203\254\343\202\244\343\202\242\343\202\246\343\203\210.py" create mode 100644 "day1/01_streamlit_UI/\345\237\272\346\234\254UI.py" create mode 160000 day1/02_streamlit_app/lecture-ai-engineering diff --git a/day1/.env_template b/day1/.env_template deleted file mode 100644 index 6f439c5cf..000000000 --- a/day1/.env_template +++ /dev/null @@ -1,2 +0,0 @@ -HUGGINGFACE_TOKEN="hf-********" -NGROK_TOKEN="********" \ No newline at end of file diff --git a/day1/01_streamlit_UI/app.py b/day1/01_streamlit_UI/app.py index dcfbe6fec..b1ca13fc9 100644 --- a/day1/01_streamlit_UI/app.py +++ b/day1/01_streamlit_UI/app.py @@ -6,11 +6,19 @@ # ============================================ # ページ設定 # ============================================ -# st.set_page_config( -# page_title="Streamlit デモ", -# layout="wide", -# initial_sidebar_state="expanded" -# ) +st.set_page_config( + page_title="Streamlit デモ", + layout="wide", + initial_sidebar_state="expanded" +) + +# ============================================ +# ナビゲーションを追加 +# ============================================ +st.sidebar.selectbox( + "体験したい機能を選んでください", + ["基本UI", "レイアウト", "グラフ表示", "ファイルアップロード"] +) # ============================================ # タイトルと説明 @@ -36,56 +44,56 @@ st.write(f"こんにちは、{name}さん!") # ボタン -# st.subheader("ボタン") -# if st.button("クリックしてください"): -# st.success("ボタンがクリックされました!") +st.subheader("ボタン") +if st.button("クリックしてください"): + st.success("ボタンがクリックされました!") # チェックボックス -# st.subheader("チェックボックス") -# if st.checkbox("チェックを入れると追加コンテンツが表示されます"): -# st.info("これは隠れたコンテンツです!") +st.subheader("チェックボックス") +if st.checkbox("チェックを入れると追加コンテンツが表示されます"): + st.info("これは隠れたコンテンツです!") # スライダー -# st.subheader("スライダー") -# age = st.slider("年齢", 0, 100, 25) -# st.write(f"あなたの年齢: {age}") +st.subheader("スライダー") +age = st.slider("年齢", 0, 100, 25) +st.write(f"あなたの年齢: {age}") # セレクトボックス -# st.subheader("セレクトボックス") -# option = st.selectbox( -# "好きなプログラミング言語は?", -# ["Python", "JavaScript", "Java", "C++", "Go", "Rust"] -# ) -# st.write(f"あなたは{option}を選びました") +st.subheader("セレクトボックス") +option = st.selectbox( + "好きなプログラミング言語は?", + ["Python", "JavaScript", "Java", "C++", "Go", "Rust"] +) +st.write(f"あなたは{option}を選びました") # ============================================ # レイアウト # ============================================ -# st.header("レイアウト") +st.header("レイアウト") # カラム -# st.subheader("カラムレイアウト") -# col1, col2 = st.columns(2) -# with col1: -# st.write("これは左カラムです") -# st.number_input("数値を入力", value=10) -# with col2: -# st.write("これは右カラムです") -# st.metric("メトリクス", "42", "2%") +st.subheader("カラムレイアウト") +col1, col2 = st.columns(2) +with col1: + st.write("これは左カラムです") + st.number_input("数値を入力", value=10) +with col2: + st.write("これは右カラムです") + st.metric("メトリクス", "42", "2%") # タブ -# st.subheader("タブ") -# tab1, tab2 = st.tabs(["第1タブ", "第2タブ"]) -# with tab1: -# st.write("これは第1タブの内容です") -# with tab2: -# st.write("これは第2タブの内容です") +st.subheader("タブ") +tab1, tab2 = st.tabs(["第1タブ", "第2タブ"]) +with tab1: + st.write("これは第1タブの内容です") +with tab2: + st.write("これは第2タブの内容です") # エクスパンダー -# st.subheader("エクスパンダー") -# with st.expander("詳細を表示"): -# st.write("これはエクスパンダー内の隠れたコンテンツです") -# st.code("print('Hello, Streamlit!')") +st.subheader("エクスパンダー") +with st.expander("詳細を表示"): + st.write("これはエクスパンダー内の隠れたコンテンツです") + st.code("print('Hello, Streamlit!')") # ============================================ # データ表示 @@ -93,92 +101,94 @@ # st.header("データの表示") # サンプルデータフレームを作成 -# df = pd.DataFrame({ -# '名前': ['田中', '鈴木', '佐藤', '高橋', '伊藤'], -# '年齢': [25, 30, 22, 28, 33], -# '都市': ['東京', '大阪', '福岡', '札幌', '名古屋'] -# }) +df = pd.DataFrame({ + '名前': ['田中', '鈴木', '佐藤', '高橋', '伊藤'], + '年齢': [25, 30, 22, 28, 33], + '都市': ['東京', '大阪', '福岡', '札幌', '名古屋'] +}) # データフレーム表示 -# st.subheader("データフレーム") -# st.dataframe(df, use_container_width=True) +st.subheader("データフレーム") +st.dataframe(df, use_container_width=True) # テーブル表示 -# st.subheader("テーブル") -# st.table(df) +st.subheader("テーブル") +st.table(df) # メトリクス表示 -# st.subheader("メトリクス") -# col1, col2, col3 = st.columns(3) -# col1.metric("温度", "23°C", "1.5°C") -# col2.metric("湿度", "45%", "-5%") -# col3.metric("気圧", "1013hPa", "0.1hPa") +st.subheader("メトリクス") +col1, col2, col3 = st.columns(3) +col1.metric("温度", "23°C", "1.5°C") +col2.metric("湿度", "45%", "-5%") +col3.metric("気圧", "1013hPa", "0.1hPa") # ============================================ # グラフ表示 # ============================================ -# st.header("グラフの表示") +st.header("グラフの表示") # ラインチャート -# st.subheader("ラインチャート") -# chart_data = pd.DataFrame( -# np.random.randn(20, 3), -# columns=['A', 'B', 'C']) -# st.line_chart(chart_data) +st.subheader("ラインチャート") +chart_data = pd.DataFrame( + np.random.randn(20, 3), + columns=['A', 'B', 'C']) +st.line_chart(chart_data) # バーチャート -# st.subheader("バーチャート") -# chart_data = pd.DataFrame({ -# 'カテゴリ': ['A', 'B', 'C', 'D'], -# '値': [10, 25, 15, 30] -# }).set_index('カテゴリ') -# st.bar_chart(chart_data) +st.subheader("バーチャート") +chart_data = pd.DataFrame({ + 'カテゴリ': ['A', 'B', 'C', 'D'], + '値': [10, 25, 15, 30] +}).set_index('カテゴリ') +st.bar_chart(chart_data) # ============================================ # インタラクティブ機能 # ============================================ -# st.header("インタラクティブ機能") +st.header("インタラクティブ機能") # プログレスバー -# st.subheader("プログレスバー") -# progress = st.progress(0) -# if st.button("進捗をシミュレート"): -# for i in range(101): -# time.sleep(0.01) -# progress.progress(i / 100) -# st.balloons() +st.subheader("プログレスバー") +progress = st.progress(0) +if st.button("進捗をシミュレート"): + for i in range(101): + time.sleep(0.01) + progress.progress(i / 100) + st.balloons() # ファイルアップロード -# st.subheader("ファイルアップロード") -# uploaded_file = st.file_uploader("ファイルをアップロード", type=["csv", "txt"]) -# if uploaded_file is not None: -# # ファイルのデータを表示 -# bytes_data = uploaded_file.getvalue() -# st.write(f"ファイルサイズ: {len(bytes_data)} bytes") -# -# # CSVの場合はデータフレームとして読み込む -# if uploaded_file.name.endswith('.csv'): -# df = pd.read_csv(uploaded_file) -# st.write("CSVデータのプレビュー:") -# st.dataframe(df.head()) +st.subheader("ファイルアップロード") +uploaded_file = st.file_uploader("ファイルをアップロード", type=["csv", "txt"]) +if uploaded_file is not None: + # ファイルのデータを表示 + bytes_data = uploaded_file.getvalue() + st.write(f"ファイルサイズ: {len(bytes_data)} bytes") + + # CSVの場合はデータフレームとして読み込む + if uploaded_file.name.endswith('.csv'): + df = pd.read_csv(uploaded_file) + st.write("CSVデータのプレビュー:") + st.dataframe(df.head()) # ============================================ # カスタマイズ # ============================================ -# st.header("スタイルのカスタマイズ") +st.header("スタイルのカスタマイズ") # カスタムCSS -# st.markdown(""" -# -# """, unsafe_allow_html=True) -# -# st.markdown('

これはカスタムCSSでスタイリングされたテキストです!

', unsafe_allow_html=True) +st.markdown(""" + +""", unsafe_allow_html=True) +#背景色の変更 + +st.markdown('

これはカスタムCSSでスタイリングされたテキストです!

', unsafe_allow_html=True) # ============================================ # デモの使用方法 diff --git a/day1/01_streamlit_UI/app_1.py b/day1/01_streamlit_UI/app_1.py new file mode 100644 index 000000000..6a4f98f4d --- /dev/null +++ b/day1/01_streamlit_UI/app_1.py @@ -0,0 +1,78 @@ +import streamlit as st +import pandas as pd +import numpy as np +import time + +# ページ設定 +st.set_page_config( + page_title="Streamlit デモ", + layout="wide", + initial_sidebar_state="expanded" +) + +# サイドバーでページ選択 +page = st.sidebar.selectbox( + "体験したい機能を選んでください", + ["基本UI", "レイアウト", "グラフ表示", "ファイルアップロード"] +) + +# メインコンテンツ切り替え +if page == "基本UI": + st.title("基本的なUI要素") + + name = st.text_input("あなたの名前", "ゲスト") + st.write(f"こんにちは、{name}さん!") + + if st.button("クリックしてください"): + st.success("ボタンがクリックされました!") + + if st.checkbox("チェックを入れると追加コンテンツが表示されます"): + st.info("これは隠れたコンテンツです!") + + age = st.slider("年齢", 0, 100, 25) + st.write(f"あなたの年齢: {age}") + + option = st.selectbox("好きな言語は?", ["Python", "JavaScript", "C++"]) + st.write(f"あなたは {option} を選びました") + +elif page == "レイアウト": + st.title("レイアウトのデモ") + + col1, col2 = st.columns(2) + with col1: + st.write("これは左カラムです") + st.number_input("数値を入力", value=10) + with col2: + st.write("これは右カラムです") + st.metric("メトリクス", "42", "2%") + + tab1, tab2 = st.tabs(["第1タブ", "第2タブ"]) + with tab1: + st.write("これは第1タブの内容です") + with tab2: + st.write("これは第2タブの内容です") + +elif page == "グラフ表示": + st.title("グラフの表示") + + chart_data = pd.DataFrame(np.random.randn(20, 3), columns=['A', 'B', 'C']) + st.line_chart(chart_data) + + bar_data = pd.DataFrame({ + 'カテゴリ': ['A', 'B', 'C', 'D'], + '値': [10, 25, 15, 30] + }).set_index('カテゴリ') + st.bar_chart(bar_data) + +elif page == "ファイルアップロード": + st.title("ファイルアップロード") + + uploaded_file = st.file_uploader("CSVまたはTXTファイルをアップロード", type=["csv", "txt"]) + if uploaded_file is not None: + st.write(f"ファイルサイズ: {len(uploaded_file.getvalue())} bytes") + + if uploaded_file.name.endswith('.csv'): + df = pd.read_csv(uploaded_file) + st.write("CSVデータのプレビュー:") + st.dataframe(df) + diff --git "a/day1/01_streamlit_UI/\343\203\225\343\202\241\343\202\244\343\203\253\343\202\242\343\203\203\343\203\227\343\203\255\343\203\274\343\203\211.py" "b/day1/01_streamlit_UI/\343\203\225\343\202\241\343\202\244\343\203\253\343\202\242\343\203\203\343\203\227\343\203\255\343\203\274\343\203\211.py" new file mode 100644 index 000000000..e69de29bb diff --git "a/day1/01_streamlit_UI/\343\203\254\343\202\244\343\202\242\343\202\246\343\203\210.py" "b/day1/01_streamlit_UI/\343\203\254\343\202\244\343\202\242\343\202\246\343\203\210.py" new file mode 100644 index 000000000..3a45af60a --- /dev/null +++ "b/day1/01_streamlit_UI/\343\203\254\343\202\244\343\202\242\343\202\246\343\203\210.py" @@ -0,0 +1,17 @@ +import streamlit as st + +st.title("レイアウトのデモ") + +col1, col2 = st.columns(2) +with col1: + st.write("これは左カラムです") + st.number_input("数値を入力", value=10) +with col2: + st.write("これは右カラムです") + st.metric("メトリクス", "42", "2%") + +tab1, tab2 = st.tabs(["第1タブ", "第2タブ"]) +with tab1: + st.write("これは第1タブの内容です") +with tab2: + st.write("これは第2タブの内容です") \ No newline at end of file diff --git "a/day1/01_streamlit_UI/\345\237\272\346\234\254UI.py" "b/day1/01_streamlit_UI/\345\237\272\346\234\254UI.py" new file mode 100644 index 000000000..63b91926d --- /dev/null +++ "b/day1/01_streamlit_UI/\345\237\272\346\234\254UI.py" @@ -0,0 +1,18 @@ +import streamlit as st + +st.title("基本的なUI要素") + +name = st.text_input("あなたの名前", "ゲスト") +st.write(f"こんにちは、{name}さん!") + +if st.button("クリックしてください"): + st.success("ボタンがクリックされました!") + +if st.checkbox("チェックを入れると追加コンテンツが表示されます"): + st.info("これは隠れたコンテンツです!") + +age = st.slider("年齢", 0, 100, 25) +st.write(f"あなたの年齢: {age}") + +option = st.selectbox("好きな言語は?", ["Python", "JavaScript", "C++"]) +st.write(f"あなたは {option} を選びました") \ No newline at end of file diff --git a/day1/02_streamlit_app/lecture-ai-engineering b/day1/02_streamlit_app/lecture-ai-engineering new file mode 160000 index 000000000..918e6187a --- /dev/null +++ b/day1/02_streamlit_app/lecture-ai-engineering @@ -0,0 +1 @@ +Subproject commit 918e6187a3d5faca6a09bbfb5659e3584a467cc7 From 0a8cb9d092ab5864079453cd685ea8d8d0d569f4 Mon Sep 17 00:00:00 2001 From: teshima shinnosuke <5123033z@g.hit-u.ac.jp> Date: Wed, 30 Apr 2025 01:45:54 +0900 Subject: [PATCH 2/3] =?UTF-8?q?=E4=B8=8D=E8=A6=81=E3=81=AA=E3=83=95?= =?UTF-8?q?=E3=82=A1=E3=82=A4=E3=83=AB=E3=82=92=E5=89=8A=E9=99=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...227\343\203\255\343\203\274\343\203\211.py" | 0 ...244\343\202\242\343\202\246\343\203\210.py" | 17 ----------------- .../\345\237\272\346\234\254UI.py" | 18 ------------------ 3 files changed, 35 deletions(-) delete mode 100644 "day1/01_streamlit_UI/\343\203\225\343\202\241\343\202\244\343\203\253\343\202\242\343\203\203\343\203\227\343\203\255\343\203\274\343\203\211.py" delete mode 100644 "day1/01_streamlit_UI/\343\203\254\343\202\244\343\202\242\343\202\246\343\203\210.py" delete mode 100644 "day1/01_streamlit_UI/\345\237\272\346\234\254UI.py" diff --git "a/day1/01_streamlit_UI/\343\203\225\343\202\241\343\202\244\343\203\253\343\202\242\343\203\203\343\203\227\343\203\255\343\203\274\343\203\211.py" "b/day1/01_streamlit_UI/\343\203\225\343\202\241\343\202\244\343\203\253\343\202\242\343\203\203\343\203\227\343\203\255\343\203\274\343\203\211.py" deleted file mode 100644 index e69de29bb..000000000 diff --git "a/day1/01_streamlit_UI/\343\203\254\343\202\244\343\202\242\343\202\246\343\203\210.py" "b/day1/01_streamlit_UI/\343\203\254\343\202\244\343\202\242\343\202\246\343\203\210.py" deleted file mode 100644 index 3a45af60a..000000000 --- "a/day1/01_streamlit_UI/\343\203\254\343\202\244\343\202\242\343\202\246\343\203\210.py" +++ /dev/null @@ -1,17 +0,0 @@ -import streamlit as st - -st.title("レイアウトのデモ") - -col1, col2 = st.columns(2) -with col1: - st.write("これは左カラムです") - st.number_input("数値を入力", value=10) -with col2: - st.write("これは右カラムです") - st.metric("メトリクス", "42", "2%") - -tab1, tab2 = st.tabs(["第1タブ", "第2タブ"]) -with tab1: - st.write("これは第1タブの内容です") -with tab2: - st.write("これは第2タブの内容です") \ No newline at end of file diff --git "a/day1/01_streamlit_UI/\345\237\272\346\234\254UI.py" "b/day1/01_streamlit_UI/\345\237\272\346\234\254UI.py" deleted file mode 100644 index 63b91926d..000000000 --- "a/day1/01_streamlit_UI/\345\237\272\346\234\254UI.py" +++ /dev/null @@ -1,18 +0,0 @@ -import streamlit as st - -st.title("基本的なUI要素") - -name = st.text_input("あなたの名前", "ゲスト") -st.write(f"こんにちは、{name}さん!") - -if st.button("クリックしてください"): - st.success("ボタンがクリックされました!") - -if st.checkbox("チェックを入れると追加コンテンツが表示されます"): - st.info("これは隠れたコンテンツです!") - -age = st.slider("年齢", 0, 100, 25) -st.write(f"あなたの年齢: {age}") - -option = st.selectbox("好きな言語は?", ["Python", "JavaScript", "C++"]) -st.write(f"あなたは {option} を選びました") \ No newline at end of file From c2ac9bc902cb100c5e3ffe776041327919aecef4 Mon Sep 17 00:00:00 2001 From: teshima shinnosuke <5123033z@g.hit-u.ac.jp> Date: Wed, 28 May 2025 15:35:44 +0900 Subject: [PATCH 3/3] Add: GitHub Actions CI for Day5 test --- .../.github/workflows/test.yml" | 26 +++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 "day1/01_streamlit_UI/day5/\346\274\224\347\277\2222/.github/workflows/test.yml" diff --git "a/day1/01_streamlit_UI/day5/\346\274\224\347\277\2222/.github/workflows/test.yml" "b/day1/01_streamlit_UI/day5/\346\274\224\347\277\2222/.github/workflows/test.yml" new file mode 100644 index 000000000..34ec2966e --- /dev/null +++ "b/day1/01_streamlit_UI/day5/\346\274\224\347\277\2222/.github/workflows/test.yml" @@ -0,0 +1,26 @@ +name: Run tests for Day5 + +on: + pull_request: + branches: [main, master, develop] + +jobs: + test: + runs-on: ubuntu-latest + steps: + - name: Check out code + uses: actions/checkout@v2 + + - name: Set up Python + uses: actions/setup-python@v2 + with: + python-version: '3.11' + + - name: Install dependencies + run: | + python -m pip install --upgrade pip + pip install scikit-learn pytest + + - name: Run test + run: | + pytest day5/演習2/test_main.py -s