feature: chatbot
Browse files- app/main.py +10 -8
app/main.py
CHANGED
@@ -1,17 +1,19 @@
|
|
1 |
from fastapi import FastAPI
|
2 |
from fastapi.responses import HTMLResponse
|
3 |
from fastapi.staticfiles import StaticFiles
|
4 |
-
from
|
5 |
|
6 |
app = FastAPI()
|
|
|
|
|
|
|
7 |
|
8 |
-
app.
|
9 |
-
|
10 |
-
@app.get("/", response_class=HTMLResponse)
|
11 |
def read_root():
|
12 |
-
with open(
|
13 |
return html_file.read()
|
14 |
|
15 |
-
@app.
|
16 |
-
def
|
17 |
-
|
|
|
|
1 |
from fastapi import FastAPI
|
2 |
from fastapi.responses import HTMLResponse
|
3 |
from fastapi.staticfiles import StaticFiles
|
4 |
+
from transformers import pipeline
|
5 |
|
6 |
app = FastAPI()
|
7 |
+
app.mount('/static', StaticFiles(directory='app/static'), name='static')
|
8 |
+
question_answerer = pipeline(task='question-answering',
|
9 |
+
model='distilbert-base-cased-distilled-squad')
|
10 |
|
11 |
+
@app.get('/', response_class=HTMLResponse)
|
|
|
|
|
12 |
def read_root():
|
13 |
+
with open('app/index.html', 'r') as html_file:
|
14 |
return html_file.read()
|
15 |
|
16 |
+
@app.post('/chatbot')
|
17 |
+
async def ask_question(question: str, context: str):
|
18 |
+
result = question_answerer(question=question, context=context)
|
19 |
+
return {'answer': result['answer']}
|