plan291037 commited on
Commit
b21f1b2
·
verified ·
1 Parent(s): f24cadf

Update app/main.py

Browse files
Files changed (1) hide show
  1. app/main.py +10 -8
app/main.py CHANGED
@@ -8,7 +8,7 @@ from pydantic import BaseModel, HttpUrl, root_validator, ValidationError
8
  from fastapi.encoders import jsonable_encoder
9
 
10
  from app.lens_images_core import translate_lens
11
- from app.lens_text_core import translate_lens_text
12
 
13
  PORT = int(os.getenv("PORT", 8080))
14
  MAX_WORKERS = int(os.getenv("MAX_WORKERS", 8))
@@ -115,7 +115,9 @@ async def health():
115
  @app.post("/translate")
116
  async def translate(job: Job):
117
  await ensure_workers_started()
118
- if job.mode not in ("lens_images", "lens_text"):
 
 
119
  raise HTTPException(400, "unsupported mode")
120
  jid = uuid.uuid4().hex
121
  job.metadata.pipeline.append(PipelineEvent(stage="received_rest", at=datetime.utcnow()))
@@ -155,8 +157,8 @@ async def ws_endpoint(ws: WebSocket):
155
 
156
  if msg.payload.mode == "lens_images":
157
  await jobq_img.put((jid, msg.payload))
158
- elif msg.payload.mode == "lens_text":
159
- await jobq_text.put((jid, msg.payload))
160
  else:
161
  await ws.send_json({"type": "error","detail": "unsupported_mode"})
162
  pending_ws.pop(jid, None)
@@ -182,8 +184,8 @@ async def worker(mode: str, q: asyncio.Queue):
182
  log.info("worker start %s mode=%s src=%s", jid, job.mode, job.src)
183
  if mode == "lens_images":
184
  res = await translate_lens(str(job.src), job.lang)
185
- elif mode == "lens_text":
186
- res = await translate_lens_text(str(job.src))
187
  else:
188
  raise RuntimeError(f"unsupported mode {mode}")
189
 
@@ -234,8 +236,8 @@ async def startup():
234
  if ENABLE_BACKGROUND_WORKERS:
235
  for _ in range(MAX_WORKERS_IMAGES):
236
  asyncio.create_task(worker("lens_images", jobq_img))
237
- for _ in range(MAX_WORKERS_TEXT):
238
- asyncio.create_task(worker("lens_text", jobq_text))
239
  asyncio.create_task(cleanup())
240
  log.info(
241
  "startup OK – %d image workers, %d text workers, TTL=%ds (workers_enabled=%s)",
 
8
  from fastapi.encoders import jsonable_encoder
9
 
10
  from app.lens_images_core import translate_lens
11
+ # from app.lens_text_core import translate_lens_text
12
 
13
  PORT = int(os.getenv("PORT", 8080))
14
  MAX_WORKERS = int(os.getenv("MAX_WORKERS", 8))
 
115
  @app.post("/translate")
116
  async def translate(job: Job):
117
  await ensure_workers_started()
118
+ # if job.mode not in ("lens_images", "lens_text"):
119
+ # raise HTTPException(400, "unsupported mode")
120
+ if job.mode != "lens_images":
121
  raise HTTPException(400, "unsupported mode")
122
  jid = uuid.uuid4().hex
123
  job.metadata.pipeline.append(PipelineEvent(stage="received_rest", at=datetime.utcnow()))
 
157
 
158
  if msg.payload.mode == "lens_images":
159
  await jobq_img.put((jid, msg.payload))
160
+ # elif msg.payload.mode == "lens_text":
161
+ # await jobq_text.put((jid, msg.payload))
162
  else:
163
  await ws.send_json({"type": "error","detail": "unsupported_mode"})
164
  pending_ws.pop(jid, None)
 
184
  log.info("worker start %s mode=%s src=%s", jid, job.mode, job.src)
185
  if mode == "lens_images":
186
  res = await translate_lens(str(job.src), job.lang)
187
+ # elif mode == "lens_text":
188
+ # res = await translate_lens_text(str(job.src))
189
  else:
190
  raise RuntimeError(f"unsupported mode {mode}")
191
 
 
236
  if ENABLE_BACKGROUND_WORKERS:
237
  for _ in range(MAX_WORKERS_IMAGES):
238
  asyncio.create_task(worker("lens_images", jobq_img))
239
+ # for _ in range(MAX_WORKERS_TEXT):
240
+ # asyncio.create_task(worker("lens_text", jobq_text))
241
  asyncio.create_task(cleanup())
242
  log.info(
243
  "startup OK – %d image workers, %d text workers, TTL=%ds (workers_enabled=%s)",