CaesarCloudSync commited on
Commit
4915e38
1 Parent(s): c9e80bb

CaesarAI Handwriting

Browse files
CaesarHandwriting/caesarhandwriting.py CHANGED
@@ -7,7 +7,7 @@ class CaesarHandWriting:
7
  def __init__(self) -> None:
8
  self.processor = TrOCRProcessor.from_pretrained('microsoft/trocr-large-handwritten')
9
  self.model = VisionEncoderDecoderModel.from_pretrained('microsoft/trocr-large-handwritten')
10
- def translate(self,url='https://fki.tic.heia-fr.ch/static/img/a01-122-02-00.jpg'):
11
  image = Image.open(requests.get(url, stream=True).raw).convert("RGB")
12
  pixel_values = self.processor(images=image, return_tensors="pt").pixel_values
13
  generated_ids = self.model.generate(pixel_values)
 
7
  def __init__(self) -> None:
8
  self.processor = TrOCRProcessor.from_pretrained('microsoft/trocr-large-handwritten')
9
  self.model = VisionEncoderDecoderModel.from_pretrained('microsoft/trocr-large-handwritten')
10
+ def translate(self,url):
11
  image = Image.open(requests.get(url, stream=True).raw).convert("RGB")
12
  pixel_values = self.processor(images=image, return_tensors="pt").pixel_values
13
  generated_ids = self.model.generate(pixel_values)
main.py CHANGED
@@ -57,9 +57,10 @@ def caesaraihome():
57
  def caesarailogo():
58
  return FileResponse(f"{CURRENT_DIR}/CaesarAILogo.png")
59
 
60
- @app.get("/caesarhandwriting")
61
- def caesaraihandwriting(url: Union[str,None]):
62
- text = caesarhandwriting.translate(url)
 
63
  return {"message":text}
64
 
65
 
 
57
  def caesarailogo():
58
  return FileResponse(f"{CURRENT_DIR}/CaesarAILogo.png")
59
 
60
+ @app.post("/caesarhandwriting")
61
+ def caesaraihandwriting(urljson : CaesarAIHandwritingModel):
62
+ urljson = dict(urljson)
63
+ text = caesarhandwriting.translate(urljson["url"])
64
  return {"message":text}
65
 
66