Spaces:
Sleeping
Sleeping
from fastapi import FastAPI, Request | |
from fastapi.responses import HTMLResponse | |
from starlette.responses import FileResponse | |
from fastapi.staticfiles import StaticFiles | |
from transformers import pipeline | |
app = FastAPI() | |
# Initialize the pipeline | |
question_answerer = pipeline("question-answering", model='distilbert-base-cased-distilled-squad') | |
# Serve static files | |
app.mount("/static", StaticFiles(directory="static", html=True), name="static") | |
# Serve index.html at the root | |
async def read_index(): | |
return FileResponse("static/index.html") | |
# Endpoint for text-to-text generation | |
async def generate_text(question: str, context: str): | |
output = question_answerer(question=question, context=context) | |
print(output) | |
return {"output": f"Answer: '{output['answer']}', score: {round(output['score'], 4)}, start: {output['start']}, end: {output['end']}"} | |