Spaces:
Sleeping
Sleeping
Commit Β·
e3e2c25
1
Parent(s): 3889675
refactor: added dto
Browse files
app.py
CHANGED
|
@@ -4,6 +4,7 @@ from fastapi.middleware.cors import CORSMiddleware
|
|
| 4 |
from extractive import ExtractiveModel, _get_summary
|
| 5 |
from cosine import CosineModel, build_summary
|
| 6 |
from abstractive import Abstractive
|
|
|
|
| 7 |
|
| 8 |
from transformers import pipeline
|
| 9 |
|
|
@@ -23,16 +24,12 @@ app.add_middleware(
|
|
| 23 |
)
|
| 24 |
|
| 25 |
|
| 26 |
-
class SummaryRequest:
|
| 27 |
-
def __init__(self, text:str, model:int) -> None:
|
| 28 |
-
self.text = text
|
| 29 |
-
self.model = model
|
| 30 |
-
|
| 31 |
|
| 32 |
@app.post("/textsummarize")
|
| 33 |
-
def summarizeText(request_body:
|
| 34 |
|
| 35 |
-
text
|
|
|
|
| 36 |
summary="error"
|
| 37 |
|
| 38 |
if model==0:
|
|
|
|
| 4 |
from extractive import ExtractiveModel, _get_summary
|
| 5 |
from cosine import CosineModel, build_summary
|
| 6 |
from abstractive import Abstractive
|
| 7 |
+
from dto import SummarizeRequest
|
| 8 |
|
| 9 |
from transformers import pipeline
|
| 10 |
|
|
|
|
| 24 |
)
|
| 25 |
|
| 26 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 27 |
|
| 28 |
@app.post("/textsummarize")
|
| 29 |
+
def summarizeText(request_body:SummarizeRequest):
|
| 30 |
|
| 31 |
+
text = request_body.text
|
| 32 |
+
model = int(request_body.model)
|
| 33 |
summary="error"
|
| 34 |
|
| 35 |
if model==0:
|
dto.py
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from datetime import datetime
|
| 2 |
+
from typing import List
|
| 3 |
+
from typing import Optional
|
| 4 |
+
|
| 5 |
+
from pydantic import BaseModel
|
| 6 |
+
from pydantic import Field
|
| 7 |
+
|
| 8 |
+
|
| 9 |
+
class SummarizeRequest(BaseModel):
|
| 10 |
+
"""Text Summarize request model."""
|
| 11 |
+
text: str = Field(..., description="The text you want to summarize", examples=["α¨α°αα«α© α¨α΅αα«α α α«α£α’αα½ α ααα£α΅ αα―αΈαα ..."])
|
| 12 |
+
model: Optional[int] = Field(None, description="model index 0 = ExtractiveModel, 1 = Cosine Similarity, 3 = Abstractive - News Headline", examples=[0,1,2])
|