diff --git a/day1/02_streamlit_app/app.py b/day1/02_streamlit_app/app.py index ba7b3b45f..11f4c4be3 100644 --- a/day1/02_streamlit_app/app.py +++ b/day1/02_streamlit_app/app.py @@ -9,7 +9,10 @@ from transformers import pipeline from config import MODEL_NAME from huggingface_hub import HfFolder +from dotenv import load_dotenv, find_dotenv + # カレントディレクトリの .env を自動読み込み +load_dotenv(find_dotenv()) # --- アプリケーション設定 --- st.set_page_config(page_title="Gemma Chatbot", layout="wide") diff --git a/day1/02_streamlit_app/bootstrap.py b/day1/02_streamlit_app/bootstrap.py new file mode 100644 index 000000000..78f694306 --- /dev/null +++ b/day1/02_streamlit_app/bootstrap.py @@ -0,0 +1,17 @@ +# .streamlit/secrets.toml ファイルを作成 +import os +import toml + +# 設定ファイル用ディレクトリを作る +os.makedirs('.streamlit', exist_ok=True) + +# 環境変数からトークンを取得して辞書にまとめる +secrets = { + "huggingface": { + "token": os.environ.get("HUGGINGFACE_TOKEN", "") + } +} + +# .streamlit/secrets.toml に書き出し +with open('.streamlit/secrets.toml', 'w') as f: + toml.dump(secrets, f) diff --git a/day1/02_streamlit_app/llm.py b/day1/02_streamlit_app/llm.py index 988002124..5fc49a4ef 100644 --- a/day1/02_streamlit_app/llm.py +++ b/day1/02_streamlit_app/llm.py @@ -15,7 +15,8 @@ def load_model(): # アクセストークンを保存 hf_token = st.secrets["huggingface"]["token"] - + # Hugging Face Hub にログインして認証情報を確実に渡す + login(hf_token) device = "cuda" if torch.cuda.is_available() else "cpu" st.info(f"Using device: {device}") # 使用デバイスを表示 pipe = pipeline( @@ -42,7 +43,7 @@ def generate_response(pipe, user_question): {"role": "user", "content": user_question}, ] # max_new_tokensを調整可能にする(例) - outputs = pipe(messages, max_new_tokens=512, do_sample=True, temperature=0.7, top_p=0.9) + outputs = pipe(messages, max_new_tokens=64, do_sample=True, temperature=0.7, top_p=0.9) # Gemmaの出力形式に合わせて調整が必要な場合がある # 最後のassistantのメッセージを取得 diff --git "a/day5/\346\274\224\347\277\2221/models/titanic_model.pkl" "b/day5/\346\274\224\347\277\2221/models/titanic_model.pkl" index 6fec87e47..b1482c9a7 100644 Binary files "a/day5/\346\274\224\347\277\2221/models/titanic_model.pkl" and "b/day5/\346\274\224\347\277\2221/models/titanic_model.pkl" differ diff --git "a/day5/\346\274\224\347\277\2222/black_check.py" "b/day5/\346\274\224\347\277\2222/black_check.py" index 3158f952d..910a40c3a 100644 --- "a/day5/\346\274\224\347\277\2222/black_check.py" +++ "b/day5/\346\274\224\347\277\2222/black_check.py" @@ -1,7 +1,18 @@ +def say_hello(name): + print("Hello," + name + "!") # greet + + +def say_hello(name): + print("Hello," + name + "!") # greet + + +def add(a, b): + return a + b + + +def add(a, b): + return a + b + -def say_hello(name):print("Hello,"+name+"!") # greet -def say_hello(name):print("Hello," + name +"!") # greet -def add( a,b):return a+b -def add( a , b ):return a+b def add(a, b): - return a+b \ No newline at end of file + return a + b diff --git "a/day5/\346\274\224\347\277\2222/models/titanic_model.pkl" "b/day5/\346\274\224\347\277\2222/models/titanic_model.pkl" index 9e1859fdf..02a80d86e 100644 Binary files "a/day5/\346\274\224\347\277\2222/models/titanic_model.pkl" and "b/day5/\346\274\224\347\277\2222/models/titanic_model.pkl" differ