Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -138,6 +138,26 @@ def safe_format_result(result) -> str:
|
|
| 138 |
except Exception as e:
|
| 139 |
return f"Error formatting result: {e}"
|
| 140 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 141 |
# Model and Device Setup
|
| 142 |
if torch.backends.mps.is_available():
|
| 143 |
device = "mps"
|
|
@@ -1899,4 +1919,15 @@ demo = gr.TabbedInterface(
|
|
| 1899 |
)
|
| 1900 |
|
| 1901 |
if __name__ == "__main__":
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1902 |
demo.launch(server_name="0.0.0.0", server_port=7860, share=False)
|
|
|
|
| 138 |
except Exception as e:
|
| 139 |
return f"Error formatting result: {e}"
|
| 140 |
|
| 141 |
+
|
| 142 |
+
from fastapi import FastAPI, Request
|
| 143 |
+
from fastapi.responses import JSONResponse
|
| 144 |
+
|
| 145 |
+
api_app = FastAPI()
|
| 146 |
+
|
| 147 |
+
@api_app.post("/multi_agent_chat")
|
| 148 |
+
async def multi_agent_chat(request: Request):
|
| 149 |
+
data = await request.json()
|
| 150 |
+
query = data.get("query")
|
| 151 |
+
result = multi_agent_chat_advanced(query)
|
| 152 |
+
return JSONResponse(content={"result": result})
|
| 153 |
+
|
| 154 |
+
@api_app.post("/multi_doc_qa")
|
| 155 |
+
async def multi_doc_qa(request: Request):
|
| 156 |
+
data = await request.json()
|
| 157 |
+
query = data.get("query")
|
| 158 |
+
result = langgraph_tab6_main(query)
|
| 159 |
+
return JSONResponse(content={"result": result})
|
| 160 |
+
|
| 161 |
# Model and Device Setup
|
| 162 |
if torch.backends.mps.is_available():
|
| 163 |
device = "mps"
|
|
|
|
| 1919 |
)
|
| 1920 |
|
| 1921 |
if __name__ == "__main__":
|
| 1922 |
+
import threading
|
| 1923 |
+
import uvicorn
|
| 1924 |
+
|
| 1925 |
+
# 開 FastAPI 在另一個 thread
|
| 1926 |
+
def run_fastapi():
|
| 1927 |
+
uvicorn.run("app:api_app", host="0.0.0.0", port=8000)
|
| 1928 |
+
|
| 1929 |
+
fastapi_thread = threading.Thread(target=run_fastapi)
|
| 1930 |
+
fastapi_thread.start()
|
| 1931 |
+
|
| 1932 |
+
# 同時跑 Gradio
|
| 1933 |
demo.launch(server_name="0.0.0.0", server_port=7860, share=False)
|