File size: 698 Bytes
8904ae0 87f49ae d2ddedd ad38076 8904ae0 ad38076 8904ae0 ad38076 8904ae0 ad38076 526f25a 8904ae0 ad38076 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 |
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']} |