wldmr commited on
Commit
568c88a
·
1 Parent(s): 29714d1

Update main.py

Browse files
Files changed (1) hide show
  1. main.py +17 -20
main.py CHANGED
@@ -1,8 +1,8 @@
1
  # main.py
 
 
2
 
3
  from fastapi import FastAPI
4
- from PIL import Image
5
- import base64
6
  from fastapi.responses import HTMLResponse, FileResponse
7
 
8
  app = FastAPI()
@@ -30,24 +30,21 @@ async def root():
30
 
31
  @app.get("/api")
32
  async def cal_api():
33
- images = []
34
-
35
- with open('workdir/lion.jpg', 'rb') as open_file:
36
- byte_content = open_file.read()
37
- base64_bytes = base64.b64encode(byte_content)
38
- base64_string = base64_bytes.decode('utf-8')
39
- images.append(base64_string)
40
-
41
- with open('workdir/cheetah.jpg', 'rb') as open_file:
42
- byte_content = open_file.read()
43
- base64_bytes = base64.b64encode(byte_content)
44
- base64_string = base64_bytes.decode('utf-8')
45
- images.append(base64_string)
46
-
47
- #image_path='lion.jpg'
48
- #pilim = Image.open(image_path)
49
- #pilimrot = pilim.rotate(45)
50
- return {"data": images}
51
 
52
  @app.get("/items/{item_id}")
53
  async def read_item(item_id):
 
1
  # main.py
2
+ from deepmultilingualpunctuation import PunctuationModel
3
+ import re
4
 
5
  from fastapi import FastAPI
 
 
6
  from fastapi.responses import HTMLResponse, FileResponse
7
 
8
  app = FastAPI()
 
30
 
31
  @app.get("/api")
32
  async def cal_api():
33
+
34
+ input_text = "my name is clara i live in berkeley california"
35
+
36
+ model = PunctuationModel()
37
+ output_text = model.restore_punctuation(input_text)
38
+
39
+ split_text = output_text.split('. ')
40
+ pcnt_file_cr = '.\n'.join(split_text)
41
+
42
+ regex1 = r"\bi\b"
43
+ regex2 = r"(?<=[.?!;])\s*\w"
44
+ regex3 = r"^\w"
45
+ pcnt_file_cr_cap = re.sub(regex3, lambda x: x.group().upper(), re.sub(regex2, lambda x: x.group().upper(), re.sub(regex1, "I", pcnt_file_cr)))
46
+
47
+ return {"data": pcnt_file_cr_cap}
 
 
 
48
 
49
  @app.get("/items/{item_id}")
50
  async def read_item(item_id):