File size: 2,433 Bytes
837fdb6 bb71dc0 837fdb6 bb71dc0 837fdb6 84ea2c9 837fdb6 84ea2c9 837fdb6 84ea2c9 bb71dc0 84ea2c9 bb71dc0 84ea2c9 bb71dc0 4619c05 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 |
import os
import summarizer as su
import nltk
from fastapi import FastAPI
from PIL import Image
import base64
from fastapi.responses import HTMLResponse, FileResponse
app = FastAPI()
@app.get("/")
async def root():
return FileResponse(path="static/index.html", media_type="text/html")
@app.get("/tubifier")
def image_mod(rpunkt_switch, link):
if len(link)==0:
return 'Error: No link provided', None
nltk_file = 'nltk_data/tokenizers/punkt.zip'
home_pc = '/Users/hujo/'
home_hf = '/home/user/'
if os.path.exists(home_pc+nltk_file) or os.path.exists(home_hf+nltk_file):
print('nltk punkt file exists in ', nltk_file)
else:
nltk.download('punkt')
#link = 'https://www.youtube.com/watch?v=lCnHfTHkhbE'
lexrank_switch = True
html = ''
images = []
html, images = su.getSummary(link, lexrank_switch, rpunkt_switch)
#images = su.getSummaryImage(link, lexrank_switch, rpunkt_switch)
print(html)
files = os.listdir('workdir/')
print('local files: ',files)
#image_path = 'workdir/lion.jpg'
#im = Image.open(image_path)
#images.append(im)
#with Image.open(open(image_path,'rb')) as im:
# images.append(im)
#images.append(im.rotate(90))
#images[0].save("newlion.png")
print('images',images)
#return html, images
return html
@app.get("/html")
async def root():
"""Basic HTML response."""
body = (
"<html>"
"<body style='padding: 10px;'>"
"<h1>Welcome to the API</h1>"
"<div>"
"Check the docs: <a href='/docs'>here</a>"
"</div>"
"</body>"
"</html>"
)
return HTMLResponse(content=body)
@app.get("/api")
async def cal_api():
images = []
with open('workdir/lion.jpg', 'rb') as open_file:
byte_content = open_file.read()
base64_bytes = base64.b64encode(byte_content)
base64_string = base64_bytes.decode('utf-8')
images.append(base64_string)
with open('workdir/cheetah.jpg', 'rb') as open_file:
byte_content = open_file.read()
base64_bytes = base64.b64encode(byte_content)
base64_string = base64_bytes.decode('utf-8')
images.append(base64_string)
#image_path='lion.jpg'
#pilim = Image.open(image_path)
#pilimrot = pilim.rotate(45)
return {"data": images}
@app.get("/items/{item_id}")
async def read_item(item_id):
return {"item_id": item_id}
|