Spaces:
Runtime error
Runtime error
File size: 965 Bytes
921a24e f989106 7b701ad 0a7b476 f989106 7b701ad 921a24e dbce713 921a24e 7b701ad 921a24e 7b701ad 921a24e dbce713 73fb0b0 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
from fastapi import FastAPI, Request
from fastapi.responses import HTMLResponse, JSONResponse
from fastapi.staticfiles import StaticFiles
from transformers import pipeline
app = FastAPI()
# Uncomment and set up the model if needed
model = pipeline('question-answering', model='bert-large-uncased-whole-word-masking-finetuned-squad', revision='main')
# Serve static files (e.g., CSS, JS, images)
app.mount("/static", StaticFiles(directory="static"), name="static")
@app.get("/", response_class=HTMLResponse)
async def home(request: Request):
with open("templates/index.html") as f:
html_content = f.read()
return HTMLResponse(content=html_content)
@app.post("/predict", response_class=JSONResponse)
async def predict(request: Request):
data = await request.json()
user_input = data.get('message')
result = model(user_input)
response_text = result[0]['generated_text']
return JSONResponse(content={'response': response_text})
|