Spaces:
Running
Running
Update main.py
Browse files
main.py
CHANGED
@@ -4,6 +4,7 @@ from fastapi.openapi.utils import get_openapi
|
|
4 |
from fastapi.openapi.docs import get_swagger_ui_html
|
5 |
from fastapi.middleware.cors import CORSMiddleware
|
6 |
from pydantic import BaseModel
|
|
|
7 |
from fastapi import Query
|
8 |
from transformers import pipeline
|
9 |
import os, logging, traceback
|
@@ -169,3 +170,24 @@ async def bulk_analyze(data: BulkReviewInput, token: str = Query(None)):
|
|
169 |
except Exception as e:
|
170 |
logging.error(f"🔥 Bulk processing failed: {traceback.format_exc()}")
|
171 |
raise HTTPException(status_code=500, detail="Failed to analyze bulk reviews")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
4 |
from fastapi.openapi.docs import get_swagger_ui_html
|
5 |
from fastapi.middleware.cors import CORSMiddleware
|
6 |
from pydantic import BaseModel
|
7 |
+
from model import answer_only
|
8 |
from fastapi import Query
|
9 |
from transformers import pipeline
|
10 |
import os, logging, traceback
|
|
|
170 |
except Exception as e:
|
171 |
logging.error(f"🔥 Bulk processing failed: {traceback.format_exc()}")
|
172 |
raise HTTPException(status_code=500, detail="Failed to analyze bulk reviews")
|
173 |
+
from model import answer_only
|
174 |
+
|
175 |
+
class FollowUpRequest(BaseModel):
|
176 |
+
text: str
|
177 |
+
question: str
|
178 |
+
verbosity: Optional[str] = "brief"
|
179 |
+
|
180 |
+
@app.post("/followup/")
|
181 |
+
async def followup(request: FollowUpRequest, x_api_key: str = Header(None)):
|
182 |
+
if x_api_key and x_api_key != VALID_API_KEY:
|
183 |
+
raise HTTPException(status_code=401, detail="Invalid API key")
|
184 |
+
|
185 |
+
if not request.question or len(request.text.split()) < 10:
|
186 |
+
raise HTTPException(status_code=400, detail="Question or text is too short.")
|
187 |
+
|
188 |
+
try:
|
189 |
+
answer = answer_only(request.text, request.question)
|
190 |
+
return {"answer": answer}
|
191 |
+
except Exception as e:
|
192 |
+
logging.error(f"❌ Follow-up failed: {traceback.format_exc()}")
|
193 |
+
raise HTTPException(status_code=500, detail="Internal Server Error during follow-up.")
|