Wills17 commited on
Commit
0bc84b2
·
verified ·
1 Parent(s): da22b61

Update FastAPI_app.py

Browse files
Files changed (1) hide show
  1. FastAPI_app.py +3 -6
FastAPI_app.py CHANGED
@@ -100,10 +100,6 @@ def load_Qwen():
100
 
101
  def generate_recipe_qwen(ingredient_names):
102
 
103
- # Check cancellation early
104
- if cancel_event.is_set():
105
- raise asyncio.CancelledError()
106
-
107
  tokenizer, model = load_Qwen()
108
 
109
  messages = [
@@ -199,6 +195,8 @@ async def run_inference_threadsafe(pil_img):
199
 
200
  async def run_qwen_threadsafe(ingredient_names):
201
  # run blocking Qwen genearation in thread
 
 
202
  return await asyncio.to_thread(generate_recipe_qwen, ingredient_names)
203
 
204
  async def run_gemini_threadsafe(gen_model, prompt):
@@ -362,8 +360,7 @@ async def generate_recipe(ingredients: str = Form(...), user_api_key: str = Form
362
  cancel_event.clear()
363
 
364
  async def _generate_recipe_task(ingredients: str, user_api_key: str):
365
- # cooperative sleep (non-blocking)
366
- await asyncio.sleep(0.01) # small yield; removed long blocking sleeps
367
  try:
368
  ingredient_names = [ing.strip() for ing in ingredients.split(",") if ing.strip()]
369
  if not ingredient_names:
 
100
 
101
  def generate_recipe_qwen(ingredient_names):
102
 
 
 
 
 
103
  tokenizer, model = load_Qwen()
104
 
105
  messages = [
 
195
 
196
  async def run_qwen_threadsafe(ingredient_names):
197
  # run blocking Qwen genearation in thread
198
+ if cancel_event.is_set():
199
+ raise asyncio.CancelledError()
200
  return await asyncio.to_thread(generate_recipe_qwen, ingredient_names)
201
 
202
  async def run_gemini_threadsafe(gen_model, prompt):
 
360
  cancel_event.clear()
361
 
362
  async def _generate_recipe_task(ingredients: str, user_api_key: str):
363
+ await asyncio.sleep(0.01)
 
364
  try:
365
  ingredient_names = [ing.strip() for ing in ingredients.split(",") if ing.strip()]
366
  if not ingredient_names: