Spaces:
Runtime error
Runtime error
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") | |
async def home(request: Request): | |
with open("templates/index.html") as f: | |
html_content = f.read() | |
return HTMLResponse(content=html_content) | |
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}) | |