Refactor API endpoints by moving status to a dedicated endpoint and removing the old root endpoint; update Gradio app launch to integrate with FastAPI.
Browse files- api/fastapi_server.py +9 -3
- app.py +6 -6
api/fastapi_server.py
CHANGED
@@ -362,9 +362,9 @@ def load_knowledge_base():
|
|
362 |
return None
|
363 |
|
364 |
# --------------- API Endpoints ---------------
|
365 |
-
@app.get("/")
|
366 |
-
async def
|
367 |
-
"""
|
368 |
vector_store_exists = os.path.exists(os.path.join(VECTOR_STORE_PATH, "index.faiss"))
|
369 |
|
370 |
return {
|
@@ -373,6 +373,12 @@ async def root():
|
|
373 |
"kb_info": kb_info if vector_store_exists else None
|
374 |
}
|
375 |
|
|
|
|
|
|
|
|
|
|
|
|
|
376 |
@app.get("/health")
|
377 |
async def health_check():
|
378 |
"""Health check endpoint"""
|
|
|
362 |
return None
|
363 |
|
364 |
# --------------- API Endpoints ---------------
|
365 |
+
@app.get("/api/status") # Перемещаем статус на отдельный endpoint
|
366 |
+
async def status():
|
367 |
+
"""Status endpoint that shows app status"""
|
368 |
vector_store_exists = os.path.exists(os.path.join(VECTOR_STORE_PATH, "index.faiss"))
|
369 |
|
370 |
return {
|
|
|
373 |
"kb_info": kb_info if vector_store_exists else None
|
374 |
}
|
375 |
|
376 |
+
# Удаляем или комментируем старый root endpoint
|
377 |
+
# @app.get("/")
|
378 |
+
# async def root():
|
379 |
+
# """Root endpoint that shows app status"""
|
380 |
+
# ...
|
381 |
+
|
382 |
@app.get("/health")
|
383 |
async def health_check():
|
384 |
"""Health check endpoint"""
|
app.py
CHANGED
@@ -187,11 +187,11 @@ with demo:
|
|
187 |
build_kb_btn.click(build_kb, inputs=None, outputs=kb_status)
|
188 |
check_status_btn.click(check_kb_status, inputs=None, outputs=kb_status)
|
189 |
|
|
|
|
|
|
|
190 |
if __name__ == "__main__":
|
191 |
-
# Launch
|
192 |
-
|
193 |
-
|
194 |
-
server_port=7861, # Using different port from FastAPI
|
195 |
-
share=False
|
196 |
-
)
|
197 |
#demo.launch(server_name="0.0.0.0", server_port=7860, share=False)
|
|
|
187 |
build_kb_btn.click(build_kb, inputs=None, outputs=kb_status)
|
188 |
check_status_btn.click(check_kb_status, inputs=None, outputs=kb_status)
|
189 |
|
190 |
+
# Mount Gradio app to FastAPI at root path
|
191 |
+
app = gr.mount_gradio_app(fastapi_app, demo, path="/")
|
192 |
+
|
193 |
if __name__ == "__main__":
|
194 |
+
# Launch the combined app
|
195 |
+
import uvicorn
|
196 |
+
uvicorn.run(app, host="0.0.0.0", port=7860)
|
|
|
|
|
|
|
197 |
#demo.launch(server_name="0.0.0.0", server_port=7860, share=False)
|