Amitchim commited on
Commit
ee5fe56
·
verified ·
1 Parent(s): 2bcb888

Upload app.py

Browse files
Files changed (1) hide show
  1. app.py +5 -5
app.py CHANGED
@@ -41,10 +41,8 @@ try:
41
  lm.to("cuda"); DEVICE = "GPU" # ZeroGPU: bfloat16 on the GPU
42
  except Exception:
43
  lm.float(); DEVICE = "CPU" # no GPU: float32 is safer on CPU (as measured in notebook 4)
44
- # leave one CPU core free for the web server: otherwise generation uses every core, the server cannot send
45
- # the streamed updates, and the cards + text all appear at once at the end
46
- import os
47
- torch.set_num_threads(max(1, (os.cpu_count() or 2) - 1))
48
 
49
  # Intent classifier (notebook 5, section 7): logistic regression on the bge embedding -> "is this a food/drink request?"
50
  try:
@@ -215,4 +213,6 @@ with gr.Blocks(title="PachuMatch — Tel Aviv") as demo:
215
  query.submit(recommend, query, [cards, rec])
216
 
217
  if __name__ == "__main__":
218
- demo.launch(css=CSS, theme=gr.themes.Soft(primary_hue="orange"))
 
 
 
41
  lm.to("cuda"); DEVICE = "GPU" # ZeroGPU: bfloat16 on the GPU
42
  except Exception:
43
  lm.float(); DEVICE = "CPU" # no GPU: float32 is safer on CPU (as measured in notebook 4)
44
+ # (an earlier version limited torch to cpu_count-1 threads to "free a core" for streaming; the real cause
45
+ # was SSR mode - see demo.launch below - and the limit only made generation ~2x slower, so it was removed)
 
 
46
 
47
  # Intent classifier (notebook 5, section 7): logistic regression on the bge embedding -> "is this a food/drink request?"
48
  try:
 
213
  query.submit(recommend, query, [cards, rec])
214
 
215
  if __name__ == "__main__":
216
+ # ssr_mode=False: with server-side rendering, Gradio puts a Node proxy in front of Python and the
217
+ # streaming channel (SSE) returned 404 in the Space log -> no live updates, everything appeared at the end
218
+ demo.launch(css=CSS, theme=gr.themes.Soft(primary_hue="orange"), ssr_mode=False)