Spaces:
Sleeping
Sleeping
Delete backend/ai/core/app.py
Browse files- backend/ai/core/app.py +0 -48
backend/ai/core/app.py
DELETED
|
@@ -1,48 +0,0 @@
|
|
| 1 |
-
from fastapi import FastAPI, UploadFile, Form
|
| 2 |
-
from fastapi.responses import StreamingResponse
|
| 3 |
-
from fastapi.middleware.cors import CORSMiddleware
|
| 4 |
-
import asyncio
|
| 5 |
-
from logic_flow import agent
|
| 6 |
-
|
| 7 |
-
app = FastAPI(title="PINE AI Backend")
|
| 8 |
-
|
| 9 |
-
# Cho phép frontend Hugging Face gọi từ domain khác
|
| 10 |
-
app.add_middleware(
|
| 11 |
-
CORSMiddleware,
|
| 12 |
-
allow_origins=["*"], # hoặc chỉ định domain frontend
|
| 13 |
-
allow_credentials=True,
|
| 14 |
-
allow_methods=["*"],
|
| 15 |
-
allow_headers=["*"],
|
| 16 |
-
)
|
| 17 |
-
|
| 18 |
-
@app.post("/start-call")
|
| 19 |
-
async def start_call(customer_id: int = Form(...)):
|
| 20 |
-
"""
|
| 21 |
-
Bắt đầu phiên gọi mới.
|
| 22 |
-
customer_id: ID khách hàng
|
| 23 |
-
"""
|
| 24 |
-
print(f"[API] start-call cho customer_id={customer_id}")
|
| 25 |
-
return StreamingResponse(
|
| 26 |
-
agent.process_stream(str(customer_id), None),
|
| 27 |
-
media_type="text/event-stream"
|
| 28 |
-
)
|
| 29 |
-
|
| 30 |
-
@app.post("/chat-voice")
|
| 31 |
-
async def chat_voice(customer_id: int = Form(...), file: UploadFile = None):
|
| 32 |
-
"""
|
| 33 |
-
Nhận audio từ frontend và trả kết quả streaming
|
| 34 |
-
"""
|
| 35 |
-
if not file:
|
| 36 |
-
return {"error": "Thiếu file audio"}
|
| 37 |
-
|
| 38 |
-
audio_bytes = await file.read()
|
| 39 |
-
print(f"[API] chat-voice cho customer_id={customer_id}, size={len(audio_bytes)} bytes")
|
| 40 |
-
return StreamingResponse(
|
| 41 |
-
agent.process_stream(str(customer_id), audio_bytes),
|
| 42 |
-
media_type="text/event-stream"
|
| 43 |
-
)
|
| 44 |
-
|
| 45 |
-
# Test health check
|
| 46 |
-
@app.get("/health")
|
| 47 |
-
def health():
|
| 48 |
-
return {"status": "ok"}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|