Spaces:
Running

Masuhaibani commited on
Commit
c87a4dd
·
verified ·
1 Parent(s): d7e7359

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +15 -1
app.py CHANGED
@@ -1,4 +1,5 @@
1
 
 
2
  import re
3
  import gradio as gr
4
  from typing import List, Tuple, Union
@@ -12,7 +13,7 @@ DEVICE = "cuda" if torch.cuda.is_available() else "cpu"
12
  DTYPE = torch.float16 if DEVICE == "cuda" else torch.float32
13
 
14
  # سعة السياق (input + output). غيّرها إذا موديلك مختلف.
15
- CTX_LIMIT = 2880
16
  RESERVE_TOKENS = 64 # هامش أمان
17
 
18
  # ============== Load model/tokenizer ==============
@@ -138,6 +139,19 @@ with gr.Blocks() as demo:
138
  allow_flagging="never",
139
  api_name="chat" # 👈 مهم جداً يطابق "/chat"
140
  )
 
 
 
 
 
 
 
 
 
 
 
 
 
141
 
142
  if __name__ == "__main__":
143
  demo.launch()
 
1
 
2
+ import os
3
  import re
4
  import gradio as gr
5
  from typing import List, Tuple, Union
 
13
  DTYPE = torch.float16 if DEVICE == "cuda" else torch.float32
14
 
15
  # سعة السياق (input + output). غيّرها إذا موديلك مختلف.
16
+ CTX_LIMIT = 2000
17
  RESERVE_TOKENS = 64 # هامش أمان
18
 
19
  # ============== Load model/tokenizer ==============
 
139
  allow_flagging="never",
140
  api_name="chat" # 👈 مهم جداً يطابق "/chat"
141
  )
142
+ def _sanitize_threads():
143
+ # أصلح أي قيم غير صالحة
144
+ for k in ["OMP_NUM_THREADS", "OPENBLAS_NUM_THREADS", "MKL_NUM_THREADS", "NUMEXPR_NUM_THREADS"]:
145
+ v = os.environ.get(k, "1")
146
+ try:
147
+ v_int = int(str(v))
148
+ if v_int <= 0:
149
+ raise ValueError()
150
+ except Exception:
151
+ os.environ[k] = "1"
152
+ os.environ.setdefault("TOKENIZERS_PARALLELISM", "false")
153
+
154
+ _sanitize_threads()
155
 
156
  if __name__ == "__main__":
157
  demo.launch()