nexusai-v3 / main.py
suneeln-duke's picture
f
6c57304
raw
history blame
1.18 kB
from fastapi import FastAPI
import os
from langchain.document_loaders import DirectoryLoader
import wandb
import huggingface_hub
from scripts.summarization import falcon_summ
from scripts.decision_clf import seq_clf
from scripts.path_gen import paths_gen
from scripts.text_gen import story_gen
app = FastAPI()
wandb.login(key = os.getenv('wandb_key'))
huggingface_hub.login(token = os.getenv('hf_key'))
os.environ['OPENAI_API_KEY'] = os.getenv('openapi_key')
summarizer = falcon_summ.prep_pipeline()
token_path= 'models/dec_clf/tokenizer.pkl'
model_path = 'models/dec_clf/nlp.h5'
chunks = paths_gen.get_chunks("data/dune.pdf")
db = paths_gen.get_vectordb(chunks)
@app.get("/hello")
def hello():
return {"message": "Hello World"}
@app.post("/summ")
def summ(text: str):
return { "summary": falcon_summ.gen_summary(summarizer, text)}
@app.post("/clf")
def clf(text: str):
return {"decision": seq_clf.predict(text, model_path, token_path)}
@app.post("/gen_path")
def gen_path(text: str):
return paths_gen.gen_sample(text, db)
@app.post("/gen_story")
def gen_story(text: str, decision: str):
return story_gen.gen_sample(text, decision, db)