bibibi12345 commited on
Commit
fe650c7
·
1 Parent(s): 92fb831

global key concurrency problem

Browse files
Files changed (1) hide show
  1. app.py +10 -8
app.py CHANGED
@@ -70,12 +70,13 @@ async def process_fal_request(request_id, model_endpoint, fal_arguments, api_key
70
  print(f"[DEBUG] Model endpoint: {model_endpoint}")
71
  print(f"[DEBUG] Arguments: {json.dumps(fal_arguments, indent=2)[:500]}...") # First 500 chars
72
 
73
- # Set API key for this request
74
- os.environ['FAL_KEY'] = api_key
75
-
76
- # Submit the request asynchronously
77
- print(f"[DEBUG] Submitting to FAL API...")
78
- handler = await fal_client.submit_async(
 
79
  model_endpoint,
80
  arguments=fal_arguments,
81
  )
@@ -392,8 +393,9 @@ def upload_file():
392
 
393
  async def upload_file_to_fal_async(file_path, api_key):
394
  """Helper function to upload a file to FAL storage"""
395
- os.environ['FAL_KEY'] = api_key
396
- return await fal_client.upload_file_async(file_path)
 
397
 
398
  def upload_to_fal_sync(file_path, api_key):
399
  """Run upload coroutine on the shared background event loop"""
 
70
  print(f"[DEBUG] Model endpoint: {model_endpoint}")
71
  print(f"[DEBUG] Arguments: {json.dumps(fal_arguments, indent=2)[:500]}...") # First 500 chars
72
 
73
+ # Build per-request client with explicit key to avoid global env mutation
74
+ print(f"[DEBUG] Creating AsyncClient with per-request key (not using env var)")
75
+ client = fal_client.AsyncClient(key=api_key)
76
+
77
+ # Submit the request asynchronously using the per-request client
78
+ print(f"[DEBUG] Submitting to FAL API via AsyncClient.submit...")
79
+ handler = await client.submit(
80
  model_endpoint,
81
  arguments=fal_arguments,
82
  )
 
393
 
394
  async def upload_file_to_fal_async(file_path, api_key):
395
  """Helper function to upload a file to FAL storage"""
396
+ # Use per-request AsyncClient with explicit key to avoid global env mutation
397
+ client = fal_client.AsyncClient(key=api_key)
398
+ return await client.upload_file(file_path)
399
 
400
  def upload_to_fal_sync(file_path, api_key):
401
  """Run upload coroutine on the shared background event loop"""