add api for all
Browse files
app.py
CHANGED
|
@@ -9,7 +9,7 @@ from langchain_openai import ChatOpenAI, OpenAIEmbeddings
|
|
| 9 |
from langchain_chroma import Chroma
|
| 10 |
from langchain.schema import HumanMessage, SystemMessage
|
| 11 |
from tiktoken import encoding_for_model
|
| 12 |
-
from fastapi import FastAPI, HTTPException
|
| 13 |
from fastapi.middleware.cors import CORSMiddleware
|
| 14 |
from pydantic import BaseModel
|
| 15 |
import uvicorn
|
|
@@ -240,6 +240,7 @@ class ChatRequest(BaseModel):
|
|
| 240 |
temperature: float = 0.7
|
| 241 |
top_p: float = 1.0
|
| 242 |
|
|
|
|
| 243 |
@app_api.post("/chat")
|
| 244 |
def chat(request: ChatRequest):
|
| 245 |
try:
|
|
@@ -257,8 +258,43 @@ def chat(request: ChatRequest):
|
|
| 257 |
except Exception as e:
|
| 258 |
raise HTTPException(status_code=500, detail=str(e))
|
| 259 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 260 |
|
| 261 |
|
|
|
|
| 262 |
def run_fastapi():
|
| 263 |
uvicorn.run(app_api,host="0.0.0.0",port=7860)
|
| 264 |
|
|
|
|
| 9 |
from langchain_chroma import Chroma
|
| 10 |
from langchain.schema import HumanMessage, SystemMessage
|
| 11 |
from tiktoken import encoding_for_model
|
| 12 |
+
from fastapi import FastAPI,UploadFile,File, HTTPException
|
| 13 |
from fastapi.middleware.cors import CORSMiddleware
|
| 14 |
from pydantic import BaseModel
|
| 15 |
import uvicorn
|
|
|
|
| 240 |
temperature: float = 0.7
|
| 241 |
top_p: float = 1.0
|
| 242 |
|
| 243 |
+
# -- Chatbot
|
| 244 |
@app_api.post("/chat")
|
| 245 |
def chat(request: ChatRequest):
|
| 246 |
try:
|
|
|
|
| 258 |
except Exception as e:
|
| 259 |
raise HTTPException(status_code=500, detail=str(e))
|
| 260 |
|
| 261 |
+
# -- Extract ID CARD
|
| 262 |
+
@app_api.post("/extract-id-card-info")
|
| 263 |
+
async def extract_id_card_info_api(file: UploadFile = File(...)):
|
| 264 |
+
try:
|
| 265 |
+
contents = await file.read()
|
| 266 |
+
image = Image.open(BytesIO(contents))
|
| 267 |
+
result = extract_identity_card_info(image)
|
| 268 |
+
return {"status": "success", "data": result}
|
| 269 |
+
except Exception as e:
|
| 270 |
+
raise HTTPException(status_code=500, detail=str(e))
|
| 271 |
+
|
| 272 |
+
# -- Exctract vehicle info
|
| 273 |
+
@app_api.post("/extract-vehicle-info")
|
| 274 |
+
async def extract_vehicle_info_api(file: UploadFile = File(...)):
|
| 275 |
+
try:
|
| 276 |
+
contents = await file.read()
|
| 277 |
+
image = Image.open(BytesIO(contents))
|
| 278 |
+
result = extract_vehicle_info(image)
|
| 279 |
+
return {"status": "success", "data": result}
|
| 280 |
+
except Exception as e:
|
| 281 |
+
raise HTTPException(status_code=500, detail=str(e))
|
| 282 |
+
|
| 283 |
+
|
| 284 |
+
# -- Complaint Classification
|
| 285 |
+
class ComplaintRequest(BaseModel):
|
| 286 |
+
text: str
|
| 287 |
+
|
| 288 |
+
@app_api.post("/classify-complaint")
|
| 289 |
+
def classify_complaint_api(request: ComplaintRequest):
|
| 290 |
+
try:
|
| 291 |
+
result = classify_complaint(request.text)
|
| 292 |
+
return {"status": "success", "category": result}
|
| 293 |
+
except Exception as e:
|
| 294 |
+
raise HTTPException(status_code=500, detail=str(e))
|
| 295 |
|
| 296 |
|
| 297 |
+
# -- Run Fast API
|
| 298 |
def run_fastapi():
|
| 299 |
uvicorn.run(app_api,host="0.0.0.0",port=7860)
|
| 300 |
|