Spaces:
Sleeping
Sleeping
LucasAguetai
commited on
Commit
·
e0724f2
1
Parent(s):
2974ccd
fix post url
Browse files- app.py +20 -21
- requirements.txt +2 -1
app.py
CHANGED
|
@@ -1,4 +1,4 @@
|
|
| 1 |
-
from fastapi import FastAPI, HTTPException, UploadFile
|
| 2 |
from fastapi.middleware.cors import CORSMiddleware
|
| 3 |
from fastapi import FastAPI, UploadFile
|
| 4 |
from typing import Union
|
|
@@ -8,6 +8,7 @@ from modeles import bert, squeezebert, deberta, loadSqueeze
|
|
| 8 |
from uploadFile import file_to_text
|
| 9 |
from typing import List
|
| 10 |
from transformers import pipeline
|
|
|
|
| 11 |
|
| 12 |
|
| 13 |
|
|
@@ -21,7 +22,17 @@ app.add_middleware(
|
|
| 21 |
allow_headers=["*"],
|
| 22 |
)
|
| 23 |
|
|
|
|
|
|
|
|
|
|
| 24 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 25 |
|
| 26 |
pipBert = pipeline('question-answering', model="ALOQAS/bert-large-uncased-finetuned-squad-v2", tokenizer="ALOQAS/bert-large-uncased-finetuned-squad-v2")
|
| 27 |
pipDeberta = pipeline('question-answering', model="ALOQAS/deberta-large-finetuned-squad-v2", tokenizer="ALOQAS/deberta-large-finetuned-squad-v2")
|
|
@@ -33,12 +44,12 @@ async def root():
|
|
| 33 |
|
| 34 |
|
| 35 |
@app.post("/uploadfile/")
|
| 36 |
-
async def create_upload_file(files: List[UploadFile],
|
| 37 |
res = []
|
| 38 |
for file in files:
|
| 39 |
fileToText = await file_to_text(file)
|
| 40 |
|
| 41 |
-
res.append({"model": model, "texte":
|
| 42 |
|
| 43 |
return res
|
| 44 |
|
|
@@ -54,14 +65,10 @@ async def create_upload_file(texte: str, model: str):
|
|
| 54 |
|
| 55 |
return {"model": model, "texte": texte}
|
| 56 |
|
| 57 |
-
# # Modèle Pydantic pour les requêtes SqueezeBERT
|
| 58 |
-
# class SqueezeBERTRequest(BaseModel):
|
| 59 |
-
# context: str
|
| 60 |
-
# question: str
|
| 61 |
@app.post("/squeezebert/")
|
| 62 |
-
async def qasqueezebert(
|
| 63 |
try:
|
| 64 |
-
squeezebert_answer = squeezebert(context, question, model, tokenizer)
|
| 65 |
if squeezebert_answer:
|
| 66 |
return squeezebert_answer
|
| 67 |
else:
|
|
@@ -69,14 +76,10 @@ async def qasqueezebert(context: str, question: str):
|
|
| 69 |
except Exception as e:
|
| 70 |
raise HTTPException(status_code=500, detail=f"An error occurred: {str(e)}")
|
| 71 |
|
| 72 |
-
# # Modèle Pydantic pour les requêtes BERT
|
| 73 |
-
# class BERTRequest(BaseModel):
|
| 74 |
-
# context: str
|
| 75 |
-
# question: str
|
| 76 |
@app.post("/bert/")
|
| 77 |
-
async def qabert(
|
| 78 |
try:
|
| 79 |
-
bert_answer = bert(context, question, pipBert)
|
| 80 |
if bert_answer:
|
| 81 |
return bert_answer
|
| 82 |
else:
|
|
@@ -84,14 +87,10 @@ async def qabert(context: str, question: str):
|
|
| 84 |
except Exception as e:
|
| 85 |
raise HTTPException(status_code=500, detail=f"An error occurred: {str(e)}")
|
| 86 |
|
| 87 |
-
# # Modèle Pydantic pour les requêtes DeBERTa
|
| 88 |
-
# class DeBERTaRequest(BaseModel):
|
| 89 |
-
# context: str
|
| 90 |
-
# question: str
|
| 91 |
@app.post("/deberta-v2/")
|
| 92 |
-
async def qadeberta(
|
| 93 |
try:
|
| 94 |
-
deberta_answer = deberta(context, question, pipDeberta)
|
| 95 |
if deberta_answer:
|
| 96 |
return deberta_answer
|
| 97 |
else:
|
|
|
|
| 1 |
+
from fastapi import FastAPI, HTTPException, UploadFile, File, Form, Depends
|
| 2 |
from fastapi.middleware.cors import CORSMiddleware
|
| 3 |
from fastapi import FastAPI, UploadFile
|
| 4 |
from typing import Union
|
|
|
|
| 8 |
from uploadFile import file_to_text
|
| 9 |
from typing import List
|
| 10 |
from transformers import pipeline
|
| 11 |
+
from pydantic import BaseModel
|
| 12 |
|
| 13 |
|
| 14 |
|
|
|
|
| 22 |
allow_headers=["*"],
|
| 23 |
)
|
| 24 |
|
| 25 |
+
class SqueezeBERTRequest(BaseModel):
|
| 26 |
+
context: str
|
| 27 |
+
question: str
|
| 28 |
|
| 29 |
+
class BERTRequest(BaseModel):
|
| 30 |
+
context: str
|
| 31 |
+
question: str
|
| 32 |
+
|
| 33 |
+
class DeBERTaRequest(BaseModel):
|
| 34 |
+
context: str
|
| 35 |
+
question: str
|
| 36 |
|
| 37 |
pipBert = pipeline('question-answering', model="ALOQAS/bert-large-uncased-finetuned-squad-v2", tokenizer="ALOQAS/bert-large-uncased-finetuned-squad-v2")
|
| 38 |
pipDeberta = pipeline('question-answering', model="ALOQAS/deberta-large-finetuned-squad-v2", tokenizer="ALOQAS/deberta-large-finetuned-squad-v2")
|
|
|
|
| 44 |
|
| 45 |
|
| 46 |
@app.post("/uploadfile/")
|
| 47 |
+
async def create_upload_file(files: List[UploadFile], question: str, model: str):
|
| 48 |
res = []
|
| 49 |
for file in files:
|
| 50 |
fileToText = await file_to_text(file)
|
| 51 |
|
| 52 |
+
res.append({"model": model, "texte": question, "filename": file.filename, "file_to_text": fileToText})
|
| 53 |
|
| 54 |
return res
|
| 55 |
|
|
|
|
| 65 |
|
| 66 |
return {"model": model, "texte": texte}
|
| 67 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 68 |
@app.post("/squeezebert/")
|
| 69 |
+
async def qasqueezebert(request: SqueezeBERTRequest):
|
| 70 |
try:
|
| 71 |
+
squeezebert_answer = squeezebert(request.context, request.question, model, tokenizer)
|
| 72 |
if squeezebert_answer:
|
| 73 |
return squeezebert_answer
|
| 74 |
else:
|
|
|
|
| 76 |
except Exception as e:
|
| 77 |
raise HTTPException(status_code=500, detail=f"An error occurred: {str(e)}")
|
| 78 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 79 |
@app.post("/bert/")
|
| 80 |
+
async def qabert(request: BERTRequest):
|
| 81 |
try:
|
| 82 |
+
bert_answer = bert(request.context, request.question, pipBert)
|
| 83 |
if bert_answer:
|
| 84 |
return bert_answer
|
| 85 |
else:
|
|
|
|
| 87 |
except Exception as e:
|
| 88 |
raise HTTPException(status_code=500, detail=f"An error occurred: {str(e)}")
|
| 89 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 90 |
@app.post("/deberta-v2/")
|
| 91 |
+
async def qadeberta(request: DeBERTaRequest):
|
| 92 |
try:
|
| 93 |
+
deberta_answer = deberta(request.context, request.question, pipDeberta)
|
| 94 |
if deberta_answer:
|
| 95 |
return deberta_answer
|
| 96 |
else:
|
requirements.txt
CHANGED
|
@@ -12,4 +12,5 @@ PyMuPDF
|
|
| 12 |
chardet
|
| 13 |
frontend
|
| 14 |
typing
|
| 15 |
-
torch
|
|
|
|
|
|
| 12 |
chardet
|
| 13 |
frontend
|
| 14 |
typing
|
| 15 |
+
torch
|
| 16 |
+
pydantic
|