Spaces:
Sleeping
Sleeping
ksvmuralidhar
commited on
Commit
•
9590cb2
1
Parent(s):
159519c
Update api.py
Browse files
api.py
CHANGED
@@ -117,15 +117,15 @@ summ_tokenizer, summ_model = load_summarizer_models()
|
|
117 |
|
118 |
|
119 |
class URLList(BaseModel):
|
120 |
-
urls: List[str]
|
121 |
-
key: str
|
122 |
|
123 |
class Summary(BaseModel):
|
124 |
-
urls: List[str]
|
125 |
-
scraped_texts: List[str]
|
126 |
-
scrape_errors: List[str]
|
127 |
-
summaries: List[str]
|
128 |
-
summarizer_error: str
|
129 |
|
130 |
|
131 |
class NewsSummarizerAPIAuthenticationError(Exception):
|
@@ -137,7 +137,26 @@ def authenticate_key(api_key: str):
|
|
137 |
raise NewsSummarizerAPIAuthenticationError("Authentication error: Invalid API key.")
|
138 |
|
139 |
|
140 |
-
@app.post("/generate_summary/", response_model=List[Summary]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
141 |
async def read_items(q: URLList):
|
142 |
try:
|
143 |
logging.warning("Entering read_items()")
|
|
|
117 |
|
118 |
|
119 |
class URLList(BaseModel):
|
120 |
+
urls: List[str] = Field(..., description="List of URLs of news articles")
|
121 |
+
key: str = Field(..., description="Authentication Key")
|
122 |
|
123 |
class Summary(BaseModel):
|
124 |
+
urls: List[str] = Field(..., description="List of URLs of news articles")
|
125 |
+
scraped_texts: List[str] = Field(..., description="List of scraped text from input URLs")
|
126 |
+
scrape_errors: List[str] = Field("", description="List of errors raised during scraping. One item for corresponding URL")
|
127 |
+
summaries: List[str] = Field(..., description="List of generated summaries of news articles")
|
128 |
+
summarizer_error: str = Field("", description="String specifying error raised during summary.")
|
129 |
|
130 |
|
131 |
class NewsSummarizerAPIAuthenticationError(Exception):
|
|
|
137 |
raise NewsSummarizerAPIAuthenticationError("Authentication error: Invalid API key.")
|
138 |
|
139 |
|
140 |
+
@app.post("/generate_summary/", response_model=List[Summary],
|
141 |
+
responses={
|
142 |
+
200: {
|
143 |
+
"description": "List of summaries for each URL",
|
144 |
+
"content": {
|
145 |
+
"application/json": {
|
146 |
+
"schema": List[Summary]
|
147 |
+
}
|
148 |
+
}
|
149 |
+
},
|
150 |
+
|
151 |
+
401: {
|
152 |
+
"description": "Authentication Error: Wrong key",
|
153 |
+
"content": {
|
154 |
+
"application/json": {
|
155 |
+
"schema": List[Summary]
|
156 |
+
}
|
157 |
+
}
|
158 |
+
}
|
159 |
+
})
|
160 |
async def read_items(q: URLList):
|
161 |
try:
|
162 |
logging.warning("Entering read_items()")
|