uwe311 commited on
Commit
f976808
·
1 Parent(s): 0670603

Fix: subprocess install missing deps (transformers, bitsandbytes, accelerate)

Browse files
Files changed (1) hide show
  1. app.py +17 -6
app.py CHANGED
@@ -1,3 +1,20 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  import spaces
2
  import torch
3
  from transformers import AutoModelForCausalLM, AutoTokenizer, BitsAndBytesConfig
@@ -62,7 +79,6 @@ def chat(message, history, system_prompt, temperature):
62
  if not message.strip():
63
  return history
64
 
65
- # Build messages array from history
66
  messages = []
67
  if system_prompt:
68
  messages.append({"role": "system", "content": system_prompt})
@@ -73,10 +89,7 @@ def chat(message, history, system_prompt, temperature):
73
  messages.append({"role": "assistant", "content": assistant_msg})
74
  messages.append({"role": "user", "content": message})
75
 
76
- # Generate (this triggers @spaces.GPU)
77
  response = generate_response(messages, temperature, MAX_TOKENS)
78
-
79
- # Update history
80
  history.append((message, response))
81
  return history
82
 
@@ -133,7 +146,6 @@ with gr.Blocks(
133
  - **Temperature:** 0.6 (Standard für Coding)
134
  """)
135
 
136
- # Events
137
  submit.click(
138
  fn=chat,
139
  inputs=[msg, chatbot, system_prompt, temperature],
@@ -154,6 +166,5 @@ with gr.Blocks(
154
 
155
  clear_btn.click(fn=lambda: None, outputs=[chatbot])
156
 
157
-
158
  if __name__ == "__main__":
159
  demo.launch()
 
1
+ import subprocess, sys, importlib
2
+
3
+ def ensure_deps():
4
+ """Install missing dependencies at startup."""
5
+ needed = {
6
+ "transformers": "transformers>=4.50.0",
7
+ "bitsandbytes": "bitsandbytes>=0.45.0",
8
+ "accelerate": "accelerate>=1.5.0",
9
+ }
10
+ missing = [pkg for mod, pkg in needed.items() if importlib.util.find_spec(mod) is None]
11
+ if missing:
12
+ print(f"📦 Installiere fehlende Dependencies: {missing}")
13
+ subprocess.check_call([sys.executable, "-m", "pip", "install", "--no-cache-dir"] + missing)
14
+ print("✅ Dependencies installiert!")
15
+
16
+ ensure_deps()
17
+
18
  import spaces
19
  import torch
20
  from transformers import AutoModelForCausalLM, AutoTokenizer, BitsAndBytesConfig
 
79
  if not message.strip():
80
  return history
81
 
 
82
  messages = []
83
  if system_prompt:
84
  messages.append({"role": "system", "content": system_prompt})
 
89
  messages.append({"role": "assistant", "content": assistant_msg})
90
  messages.append({"role": "user", "content": message})
91
 
 
92
  response = generate_response(messages, temperature, MAX_TOKENS)
 
 
93
  history.append((message, response))
94
  return history
95
 
 
146
  - **Temperature:** 0.6 (Standard für Coding)
147
  """)
148
 
 
149
  submit.click(
150
  fn=chat,
151
  inputs=[msg, chatbot, system_prompt, temperature],
 
166
 
167
  clear_btn.click(fn=lambda: None, outputs=[chatbot])
168
 
 
169
  if __name__ == "__main__":
170
  demo.launch()