alan5543 commited on
Commit
23f0273
·
1 Parent(s): 668170f
Files changed (1) hide show
  1. app.py +5 -21
app.py CHANGED
@@ -1,6 +1,5 @@
1
  from mcp.server.fastmcp import FastMCP
2
  from gradio_client import Client
3
- from fastapi import FastAPI
4
  import uvicorn
5
  import logging
6
 
@@ -8,9 +7,6 @@ import logging
8
  logging.basicConfig(level=logging.INFO)
9
  logger = logging.getLogger(__name__)
10
 
11
- # Initialize FastAPI app as a fallback
12
- app = FastAPI()
13
-
14
  # Initialize FastMCP server
15
  try:
16
  mcp = FastMCP("gradio-spaces")
@@ -80,25 +76,13 @@ async def run_dia_tts(prompt: str, space_id: str = "ysharma/Dia-1.6B") -> str:
80
  )
81
  return result
82
 
83
- # Determine which FastAPI app to use
84
  try:
85
- fastapi_app = mcp.app # Try to use mcp.app
86
- logger.info("Using mcp.app as the FastAPI application")
87
  except AttributeError:
88
- logger.warning("mcp.app not found; attempting to use mcp.server or fallback FastAPI app")
89
- try:
90
- fastapi_app = mcp.server # Check if mcp.server is the FastAPI app
91
- logger.info("Using mcp.server as the FastAPI application")
92
- except AttributeError:
93
- logger.warning("mcp.server not found; using fallback FastAPI app")
94
- fastapi_app = app
95
- # Attempt to attach MCP routes to fallback app
96
- try:
97
- mcp.run(transport="http", app=fastapi_app)
98
- logger.info("Attached MCP routes to fallback FastAPI app")
99
- except Exception as e:
100
- logger.error("Failed to attach MCP routes to fallback app: %s", str(e))
101
- raise
102
 
103
  if __name__ == "__main__":
104
  uvicorn.run(fastapi_app, host="0.0.0.0", port=7860)
 
1
  from mcp.server.fastmcp import FastMCP
2
  from gradio_client import Client
 
3
  import uvicorn
4
  import logging
5
 
 
7
  logging.basicConfig(level=logging.INFO)
8
  logger = logging.getLogger(__name__)
9
 
 
 
 
10
  # Initialize FastMCP server
11
  try:
12
  mcp = FastMCP("gradio-spaces")
 
76
  )
77
  return result
78
 
79
+ # Use mcp.sse_app as the FastAPI application
80
  try:
81
+ fastapi_app = mcp.sse_app # Use SSE app for MCP server
82
+ logger.info("Using mcp.sse_app as the FastAPI application")
83
  except AttributeError:
84
+ logger.error("mcp.sse_app not found; FastMCP configuration may be incorrect")
85
+ raise
 
 
 
 
 
 
 
 
 
 
 
 
86
 
87
  if __name__ == "__main__":
88
  uvicorn.run(fastapi_app, host="0.0.0.0", port=7860)