Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions day1/02_streamlit_app/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")

Expand Down
17 changes: 17 additions & 0 deletions day1/02_streamlit_app/bootstrap.py
Original file line number Diff line number Diff line change
@@ -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)
5 changes: 3 additions & 2 deletions day1/02_streamlit_app/llm.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -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のメッセージを取得
Expand Down
Binary file modified day5/演習1/models/titanic_model.pkl
Binary file not shown.
21 changes: 16 additions & 5 deletions day5/演習2/black_check.py
Original file line number Diff line number Diff line change
@@ -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
return a + b
Binary file modified day5/演習2/models/titanic_model.pkl
Binary file not shown.