Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -32,7 +32,70 @@ setup_app(app)
|
|
32 |
|
33 |
# Create and include the router with dependencies
|
34 |
router = create_router(agent, logger, patients_collection, analysis_collection, users_collection, chats_collection, notifications_collection)
|
35 |
-
app.include_router(router)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
36 |
|
37 |
if __name__ == "__main__":
|
38 |
uvicorn.run(app, host="0.0.0.0", port=8000)
|
|
|
32 |
|
33 |
# Create and include the router with dependencies
|
34 |
router = create_router(agent, logger, patients_collection, analysis_collection, users_collection, chats_collection, notifications_collection)
|
35 |
+
app.include_router(router, prefix="/txagent", tags=["txagent"])
|
36 |
+
|
37 |
+
# Also include some endpoints at root level for frontend compatibility
|
38 |
+
from endpoints import ChatRequest, VoiceOutputRequest
|
39 |
+
from fastapi import Depends, HTTPException, UploadFile, File, Form
|
40 |
+
from typing import Optional
|
41 |
+
from auth import get_current_user
|
42 |
+
|
43 |
+
@app.post("/chat-stream")
|
44 |
+
async def chat_stream_root(
|
45 |
+
request: ChatRequest,
|
46 |
+
current_user: dict = Depends(get_current_user)
|
47 |
+
):
|
48 |
+
"""Chat stream endpoint at root level for frontend compatibility"""
|
49 |
+
# Import the chat stream function from endpoints
|
50 |
+
temp_router = create_router(agent, logger, patients_collection, analysis_collection, users_collection, chats_collection, notifications_collection)
|
51 |
+
|
52 |
+
# Get the chat stream endpoint function
|
53 |
+
for route in temp_router.routes:
|
54 |
+
if hasattr(route, 'path') and route.path == "/chat-stream":
|
55 |
+
return await route.endpoint(request, current_user)
|
56 |
+
|
57 |
+
raise HTTPException(status_code=404, detail="Chat stream endpoint not found")
|
58 |
+
|
59 |
+
@app.post("/voice/synthesize")
|
60 |
+
async def voice_synthesize_root(
|
61 |
+
request: dict,
|
62 |
+
current_user: dict = Depends(get_current_user)
|
63 |
+
):
|
64 |
+
"""Voice synthesis endpoint at root level for frontend compatibility"""
|
65 |
+
# Convert dict to VoiceOutputRequest
|
66 |
+
voice_request = VoiceOutputRequest(
|
67 |
+
text=request.get('text', ''),
|
68 |
+
language=request.get('language', 'en-US'),
|
69 |
+
slow=request.get('slow', False),
|
70 |
+
return_format=request.get('return_format', 'mp3')
|
71 |
+
)
|
72 |
+
|
73 |
+
# Get the voice synthesis endpoint function
|
74 |
+
temp_router = create_router(agent, logger, patients_collection, analysis_collection, users_collection, chats_collection, notifications_collection)
|
75 |
+
|
76 |
+
for route in temp_router.routes:
|
77 |
+
if hasattr(route, 'path') and route.path == "/voice/synthesize":
|
78 |
+
return await route.endpoint(voice_request, current_user)
|
79 |
+
|
80 |
+
raise HTTPException(status_code=404, detail="Voice synthesis endpoint not found")
|
81 |
+
|
82 |
+
@app.post("/analyze-report")
|
83 |
+
async def analyze_report_root(
|
84 |
+
file: UploadFile = File(...),
|
85 |
+
patient_id: Optional[str] = Form(None),
|
86 |
+
temperature: float = Form(0.5),
|
87 |
+
max_new_tokens: int = Form(1024),
|
88 |
+
current_user: dict = Depends(get_current_user)
|
89 |
+
):
|
90 |
+
"""Report analysis endpoint at root level for frontend compatibility"""
|
91 |
+
# Get the analyze report endpoint function
|
92 |
+
temp_router = create_router(agent, logger, patients_collection, analysis_collection, users_collection, chats_collection, notifications_collection)
|
93 |
+
|
94 |
+
for route in temp_router.routes:
|
95 |
+
if hasattr(route, 'path') and route.path == "/analyze-report":
|
96 |
+
return await route.endpoint(file, patient_id, temperature, max_new_tokens, current_user)
|
97 |
+
|
98 |
+
raise HTTPException(status_code=404, detail="Analyze report endpoint not found")
|
99 |
|
100 |
if __name__ == "__main__":
|
101 |
uvicorn.run(app, host="0.0.0.0", port=8000)
|