saphir / app /main.py
pytzen's picture
feature: chatbot
ad38076
raw
history blame
698 Bytes
from fastapi import FastAPI
from fastapi.responses import HTMLResponse
from fastapi.staticfiles import StaticFiles
from transformers import pipeline
app = FastAPI()
app.mount('/static', StaticFiles(directory='app/static'), name='static')
question_answerer = pipeline(task='question-answering',
model='distilbert-base-cased-distilled-squad')
@app.get('/', response_class=HTMLResponse)
def read_root():
with open('app/index.html', 'r') as html_file:
return html_file.read()
@app.post('/chatbot')
async def ask_question(question: str, context: str):
result = question_answerer(question=question, context=context)
return {'answer': result['answer']}