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/{link}") def image_mod(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' rpunkt_switch = False 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 HTMLResponse(content=html) @app.get("/html") async def root(): """Basic HTML response.""" body = ( "" "
" "