/ src / python / txtai / api / routers / textractor.py
textractor.py
 1  """
 2  Defines API paths for textractor endpoints.
 3  """
 4  
 5  from typing import List
 6  
 7  from fastapi import APIRouter, Body
 8  
 9  from .. import application
10  from ..route import EncodingAPIRoute
11  
12  router = APIRouter(route_class=EncodingAPIRoute)
13  
14  
15  @router.get("/textract")
16  def textract(file: str):
17      """
18      Extracts text from a file at path.
19  
20      Args:
21          file: file to extract text
22  
23      Returns:
24          extracted text
25      """
26  
27      return application.get().pipeline("textractor", (file,))
28  
29  
30  @router.post("/batchtextract")
31  def batchtextract(files: List[str] = Body(...)):
32      """
33      Extracts text from a file at path.
34  
35      Args:
36          files: list of files to extract text
37  
38      Returns:
39          list of extracted text
40      """
41  
42      return application.get().pipeline("textractor", (files,))