sirochild commited on
Commit
ebc78dc
·
verified ·
1 Parent(s): 5a7c79c

Upload 4 files

Browse files
Files changed (2) hide show
  1. app.py +25 -47
  2. requirements.txt +2 -1
app.py CHANGED
@@ -30,51 +30,16 @@ try:
30
  model_path = hf_hub_download(repo_id=MODEL_REPO, filename=MODEL_FILE)
31
  print(f"モデルファイルのダウンロード完了: {model_path}")
32
 
33
- # Hugging Face Spaceでの実行時はメモリ効率の良い設定を使用
34
- if os.getenv("SPACE_ID"):
35
- print("Hugging Face Space環境を検出しました。メモリ効率の良い設定を使用します。")
36
- try:
37
- # まずGPUを使用してみる
38
- swallow_model = Llama(
39
- model_path=model_path,
40
- n_ctx=2048, # コンテキスト長
41
- n_gpu_layers=-1, # 可能な限りGPUを使用
42
- n_threads=4, # スレッド数を制限
43
- verbose=False # デバッグ出力を無効化
44
- )
45
- print("GPUを使用してモデルをロードしました")
46
- except Exception as gpu_error:
47
- print(f"GPUでのロードに失敗しました: {gpu_error}")
48
- print("CPUモードでモデルをロードします")
49
- # GPUが使用できない場合はCPUのみで実行
50
- swallow_model = Llama(
51
- model_path=model_path,
52
- n_ctx=2048, # コンテキスト長
53
- n_gpu_layers=0, # GPUを使用しない
54
- n_threads=4, # スレッド数を制限
55
- verbose=False # デバッグ出力を無効化
56
- )
57
- else:
58
- # ローカル環境での実行時の設定
59
- try:
60
- # GPUを使用
61
- swallow_model = Llama(
62
- model_path=model_path,
63
- n_ctx=4096, # より長いコンテキスト長
64
- n_gpu_layers=-1, # 可能な限りGPUを使用
65
- verbose=True # デバッグ出力を有効化
66
- )
67
- print("GPUを使用してモデルをロードしました")
68
- except Exception as gpu_error:
69
- print(f"GPUでのロードに失敗しました: {gpu_error}")
70
- print("CPUモードでモデルをロードします")
71
- # GPUが使用できない場合はCPUのみで実行
72
- swallow_model = Llama(
73
- model_path=model_path,
74
- n_ctx=4096, # より長いコンテキスト長
75
- n_gpu_layers=0, # GPUを使用しない
76
- verbose=True # デバッグ出力を有効化
77
- )
78
  print("Swallowモデルのロード完了")
79
  tokenizer = None # llama-cppではtokenizerは不要
80
  except Exception as e:
@@ -448,8 +413,21 @@ def respond(message, chat_history, affection, history, scene_params):
448
  return "", chat_history, new_affection, stage_name, new_affection, new_history, final_scene_params, background_html
449
 
450
  # カスタムCSSを読み込む
451
- with open("style.css", "r") as f:
452
- custom_css = f.read()
 
 
 
 
 
 
 
 
 
 
 
 
 
453
 
454
  # Gradio 5.x用のシンプルなテーマ設定
455
  custom_theme = gr.themes.Soft(
 
30
  model_path = hf_hub_download(repo_id=MODEL_REPO, filename=MODEL_FILE)
31
  print(f"モデルファイルのダウンロード完了: {model_path}")
32
 
33
+ # 最も安全な設定でモデルをロード(CPUのみ)
34
+ print("CPUモードでモデルをロードします")
35
+ swallow_model = Llama(
36
+ model_path=model_path,
37
+ n_ctx=2048, # コンテキスト長
38
+ n_gpu_layers=0, # GPUを使用しない
39
+ n_threads=4, # スレッド数を制限
40
+ verbose=True # デバッグ出力を有効化
41
+ )
42
+ print("モデルのロード完了")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
43
  print("Swallowモデルのロード完了")
44
  tokenizer = None # llama-cppではtokenizerは不要
45
  except Exception as e:
 
413
  return "", chat_history, new_affection, stage_name, new_affection, new_history, final_scene_params, background_html
414
 
415
  # カスタムCSSを読み込む
416
+ try:
417
+ with open("style.css", "r") as f:
418
+ custom_css = f.read()
419
+ except FileNotFoundError:
420
+ print("style.cssファイルが見つかりません。デフォルトのスタイルを使用します。")
421
+ custom_css = """
422
+ /* デフォルトのスタイル */
423
+ .chatbot {
424
+ background-color: rgba(255, 255, 255, 0.7) !important;
425
+ border-radius: 12px !important;
426
+ padding: 15px !important;
427
+ box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1) !important;
428
+ margin-bottom: 20px !important;
429
+ }
430
+ """
431
 
432
  # Gradio 5.x用のシンプルなテーマ設定
433
  custom_theme = gr.themes.Soft(
requirements.txt CHANGED
@@ -6,4 +6,5 @@ fugashi
6
  unidic_lite
7
  transformers>=4.34.0
8
  protobuf>=3.20.0
9
- llama-cpp-python==0.2.19+cpuavx2
 
 
6
  unidic_lite
7
  transformers>=4.34.0
8
  protobuf>=3.20.0
9
+ # CPUのみのバージョンを使用
10
+ CMAKE_ARGS="-DLLAMA_CUBLAS=OFF" FORCE_CMAKE=1 llama-cpp-python==0.2.19