lsmpp commited on
Commit
12f3208
·
verified ·
1 Parent(s): adca048

Return target boxes, replacement text and inference defaults when loading an example

Browse files
Files changed (1) hide show
  1. app.py +13 -3
app.py CHANGED
@@ -43,6 +43,10 @@ EXAMPLES = {
43
  "english": {"label": "English editorial", "subtitle": "Four words, one poster"},
44
  "chinese": {"label": "Chinese New Year", "subtitle": "Character-level corrections"},
45
  }
 
 
 
 
46
  if os.environ.get("PIXTEXT_GRADIO") == "1":
47
  from gradio import Server
48
  app = Server(title="PixText Studio", docs_url=None, redoc_url=None)
@@ -316,7 +320,8 @@ def example_session(request: ExampleRequest):
316
  if request.example not in EXAMPLES:
317
  raise HTTPException(404, "Example not found")
318
  with Image.open(ROOT / "examples" / f"{request.example}.png") as image:
319
- return make_session(image.convert("RGB"), request.example)
 
320
 
321
 
322
  @app.post("/api/upload")
@@ -340,10 +345,15 @@ def example_targets(sid: str):
340
  session = session_for(sid)
341
  if not session["example"]:
342
  raise HTTPException(404, "No example targets for this image")
343
- rows = json.loads((ROOT / "examples" / f"{session['example']}.json").read_text())
 
 
 
 
344
  return {"regions": [{**row, "id": f"example-{i}", "enabled": True,
345
  "origin": "example", "recognized_text": "Example target"}
346
- for i, row in enumerate(rows)]}
 
347
 
348
 
349
  @app.post("/api/sessions/{sid}/detect")
 
43
  "english": {"label": "English editorial", "subtitle": "Four words, one poster"},
44
  "chinese": {"label": "Chinese New Year", "subtitle": "Character-level corrections"},
45
  }
46
+ EXAMPLE_SETTINGS = {
47
+ "variant": "meanflow", "steps": 4, "seed": 42,
48
+ "guidance": 3.3, "text_threshold": 0.5,
49
+ }
50
  if os.environ.get("PIXTEXT_GRADIO") == "1":
51
  from gradio import Server
52
  app = Server(title="PixText Studio", docs_url=None, redoc_url=None)
 
320
  if request.example not in EXAMPLES:
321
  raise HTTPException(404, "Example not found")
322
  with Image.open(ROOT / "examples" / f"{request.example}.png") as image:
323
+ session = make_session(image.convert("RGB"), request.example)
324
+ return {**session, **example_preset(request.example)}
325
 
326
 
327
  @app.post("/api/upload")
 
345
  session = session_for(sid)
346
  if not session["example"]:
347
  raise HTTPException(404, "No example targets for this image")
348
+ return example_preset(session["example"])
349
+
350
+
351
+ def example_preset(example: str):
352
+ rows = json.loads((ROOT / "examples" / f"{example}.json").read_text())
353
  return {"regions": [{**row, "id": f"example-{i}", "enabled": True,
354
  "origin": "example", "recognized_text": "Example target"}
355
+ for i, row in enumerate(rows)],
356
+ "settings": dict(EXAMPLE_SETTINGS)}
357
 
358
 
359
  @app.post("/api/sessions/{sid}/detect")