tomo2chin2 commited on
Commit
87b3a98
·
verified ·
1 Parent(s): 082f8b5

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +17 -17
app.py CHANGED
@@ -15,7 +15,7 @@ import tempfile
15
  import time
16
  import os
17
  import logging
18
- import datasets # 追加: HuggingFace Datasetsライブラリ
19
 
20
  # 正しいGemini関連のインポート
21
  import google.generativeai as genai
@@ -109,25 +109,25 @@ def enhance_font_awesome_layout(html_code):
109
  return f'<html><head>{fa_fix_css}</head>' + html_code + '</html>'
110
 
111
  def load_system_instruction():
112
- """HuggingFaceデータセットからプロンプトを読み込む"""
113
  try:
114
- # データセットを読み込む
115
- logger.info("HuggingFaceデータセットからシステムインストラクションを読み込み中...")
116
- dataset = datasets.load_dataset("tomo2chin2/GURAREKOstlyle")
117
-
118
- # prompt.txtの内容を取得
119
- if 'prompt.txt' in dataset['train']:
120
- instruction = dataset['train']['prompt.txt'][0]
121
- logger.info("システムインストラクションを正常に読み込みました")
122
- return instruction
123
- else:
124
- # prompt.txtが見つからない場合
125
- error_msg = "データセット内にprompt.txtが見つかりません"
126
- logger.error(error_msg)
127
- raise ValueError(error_msg)
128
 
129
  except Exception as e:
130
- # その他のエラーが発生した場合
131
  error_msg = f"システムインストラクションの読み込みに失敗: {str(e)}"
132
  logger.error(error_msg)
133
  raise ValueError(error_msg)
 
15
  import time
16
  import os
17
  import logging
18
+ from huggingface_hub import hf_hub_download # 追加: HuggingFace Hubからファイルを直接ダウンロード
19
 
20
  # 正しいGemini関連のインポート
21
  import google.generativeai as genai
 
109
  return f'<html><head>{fa_fix_css}</head>' + html_code + '</html>'
110
 
111
  def load_system_instruction():
112
+ """HuggingFaceリポジトリからprompt.txtを直接ダウンロードして読み込む"""
113
  try:
114
+ # ファイルを直接ダウンロード
115
+ logger.info("HuggingFaceリポジトリからprompt.txtをダウンロード中...")
116
+ file_path = hf_hub_download(
117
+ repo_id="tomo2chin2/GURAREKOstlyle",
118
+ filename="prompt.txt",
119
+ repo_type="dataset"
120
+ )
121
+
122
+ # ファイルを読み込む
123
+ with open(file_path, 'r', encoding='utf-8') as file:
124
+ instruction = file.read()
125
+
126
+ logger.info(f"システムインストラクションを正常に読み込みました: {len(instruction)}バイト")
127
+ return instruction
128
 
129
  except Exception as e:
130
+ # エラーが発生した場合
131
  error_msg = f"システムインストラクションの読み込みに失敗: {str(e)}"
132
  logger.error(error_msg)
133
  raise ValueError(error_msg)