Spaces:
Sleeping
Sleeping
LucasAguetai
commited on
Commit
·
e957e83
1
Parent(s):
11dd172
fix app.py for bert post
Browse files- __pycache__/app.cpython-312.pyc +0 -0
- __pycache__/modeles.cpython-312.pyc +0 -0
- app.py +16 -6
__pycache__/app.cpython-312.pyc
ADDED
Binary file (3.88 kB). View file
|
|
__pycache__/modeles.cpython-312.pyc
ADDED
Binary file (537 Bytes). View file
|
|
app.py
CHANGED
@@ -1,6 +1,7 @@
|
|
1 |
from fastapi import FastAPI, HTTPException, File, UploadFile
|
2 |
from fastapi.middleware.cors import CORSMiddleware
|
3 |
from typing import Annotated
|
|
|
4 |
import uvicorn
|
5 |
from fastapi import FastAPI, UploadFile, File
|
6 |
from typing import Union
|
@@ -47,13 +48,22 @@ async def create_upload_file(texte: str, model: str):
|
|
47 |
|
48 |
return {"model": model, "texte": texte}
|
49 |
|
|
|
|
|
|
|
|
|
|
|
50 |
@app.post("/bert/")
|
51 |
-
async def qabert(context, question):
|
52 |
-
|
53 |
-
|
54 |
-
|
55 |
-
|
56 |
-
|
|
|
|
|
|
|
|
|
57 |
|
58 |
def extract_data(file: UploadFile) -> Union[str, dict, list]:
|
59 |
if file.filename.endswith(".txt"):
|
|
|
1 |
from fastapi import FastAPI, HTTPException, File, UploadFile
|
2 |
from fastapi.middleware.cors import CORSMiddleware
|
3 |
from typing import Annotated
|
4 |
+
from pydantic import BaseModel
|
5 |
import uvicorn
|
6 |
from fastapi import FastAPI, UploadFile, File
|
7 |
from typing import Union
|
|
|
48 |
|
49 |
return {"model": model, "texte": texte}
|
50 |
|
51 |
+
# # Modèle Pydantic pour les requêtes BERT
|
52 |
+
# class BERTRequest(BaseModel):
|
53 |
+
# context: str
|
54 |
+
# question: str
|
55 |
+
|
56 |
@app.post("/bert/")
|
57 |
+
async def qabert(context: str, question: str):
|
58 |
+
try:
|
59 |
+
bert_answer = bert(context, question)
|
60 |
+
if bert_answer:
|
61 |
+
return bert_answer
|
62 |
+
else:
|
63 |
+
raise HTTPException(status_code=404, detail="No answer found")
|
64 |
+
except Exception as e:
|
65 |
+
raise HTTPException(status_code=500, detail=f"An error occurred: {str(e)}")
|
66 |
+
|
67 |
|
68 |
def extract_data(file: UploadFile) -> Union[str, dict, list]:
|
69 |
if file.filename.endswith(".txt"):
|