Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
|
@@ -5,6 +5,8 @@ import data_preprocess, model, pipeline
|
|
| 5 |
import os
|
| 6 |
import hashlib
|
| 7 |
import threading
|
|
|
|
|
|
|
| 8 |
|
| 9 |
# Gradio UI
|
| 10 |
#stop_flag = gr.State(value=False)
|
|
@@ -479,7 +481,7 @@ with gr.Blocks() as interface:
|
|
| 479 |
except Exception as e:
|
| 480 |
print(f"⚠️ Error processing {acc}: {e}")
|
| 481 |
return None
|
| 482 |
-
|
| 483 |
def threaded_batch_runner(file=None, text="", email=""):
|
| 484 |
print("📧 EMAIL RECEIVED:", repr(email))
|
| 485 |
import tempfile
|
|
@@ -628,8 +630,12 @@ with gr.Blocks() as interface:
|
|
| 628 |
# )
|
| 629 |
# return
|
| 630 |
|
|
|
|
|
|
|
| 631 |
num_workers = min(cpu_count(), 4) # HF free tier usually has 2 CPUs
|
| 632 |
-
|
|
|
|
|
|
|
| 633 |
|
| 634 |
try:
|
| 635 |
for result in pool.imap_unordered(
|
|
|
|
| 5 |
import os
|
| 6 |
import hashlib
|
| 7 |
import threading
|
| 8 |
+
import multiprocessing as mp
|
| 9 |
+
mp.set_start_method("spawn", force=True) # ensures workers aren't daemonic
|
| 10 |
|
| 11 |
# Gradio UI
|
| 12 |
#stop_flag = gr.State(value=False)
|
|
|
|
| 481 |
except Exception as e:
|
| 482 |
print(f"⚠️ Error processing {acc}: {e}")
|
| 483 |
return None
|
| 484 |
+
from concurrent.futures import ProcessPoolExecutor, as_completed
|
| 485 |
def threaded_batch_runner(file=None, text="", email=""):
|
| 486 |
print("📧 EMAIL RECEIVED:", repr(email))
|
| 487 |
import tempfile
|
|
|
|
| 630 |
# )
|
| 631 |
# return
|
| 632 |
|
| 633 |
+
from multiprocessing import get_context
|
| 634 |
+
|
| 635 |
num_workers = min(cpu_count(), 4) # HF free tier usually has 2 CPUs
|
| 636 |
+
ctx = get_context("spawn") # ensures workers are not daemonic
|
| 637 |
+
pool = ctx.Pool(processes=num_workers)
|
| 638 |
+
|
| 639 |
|
| 640 |
try:
|
| 641 |
for result in pool.imap_unordered(
|