Update app.py
Browse files12 unmodified lines13141516171819205 unmodified lines262728293031323334353637383940414243444546474849505152538 unmodified lines62636465666768329 unmodified lines3983994004014024034044052 unmodified lines40840941041141212 unmodified linesimport tempfileimport jsonfrom fastapi import FastAPIfrom mcp.server import Server as MCPServerfrom mcp.server.tool import Tool# Load environment variablesload_dotenv()5 unmodified lines# Create FastAPI appapp = FastAPI()# Create MCP Servermcp_server = MCPServer()# Define tool decoratorsdef tool(name: str):def decorator(func):async def wrapper(*args, **kwargs):return await func(*args, **kwargs)tool = Tool(name=name, fn=wrapper)mcp_server.add_tool(tool)return wrapperreturn decorator# Register the YouTubeTranscriber as a tool@tool("transcribe_video")async def transcribe_video(url: str, api_key: str) -> str:"""Transcribe a YouTube video."""transcriber = YouTubeTranscriber(api_key)status, transcript = transcriber.process_video(url, api_key)return transcript@tool("chat_about_video")async def chat_about_video(transcript: str, question: str, api_key: str) -> str:"""Chat about a transcribed video."""transcriber = YouTubeTranscriber(api_key)8 unmodified lines@app.get("/debug/tools")async def list_tools():"""List available MCP tools"""return {"tools": [tool.name for tool in mcp_server.tools]}class YouTubeTranscriber:def __init__(self, api_key: str = None):329 unmodified linesdemo.queue()app = gr.mount_gradio_app(app, demo, path="/")# Mount MCP servermcp_server.mount(app, path="/gradio_api/mcp")# Start the serverimport uvicorn2 unmodified lineshost="0.0.0.0",port=7880,log_level="info",reload=True # Enable auto-reload for development)12 unmodified lines13141516171819205 unmodified lines26272829303132333435363738394041424344454647484950518 unmodified lines60616263646566329 unmodified lines3963973983994004014024034042 unmodified lines40740840941041112 unmodified linesimport tempfileimport jsonfrom fastapi import FastAPIimport mcpfrom mcp import Tool# Load environment variablesload_dotenv()5 unmodified lines# Create FastAPI appapp = FastAPI()# Create tools collectiontools = []# Define tool decoratordef register_tool(name: str):def decorator(func):tool = Tool(name=name, function=func)tools.append(tool)return funcreturn decorator# Register the YouTubeTranscriber as a tool@register_tool("transcribe_video")async def transcribe_video(url: str, api_key: str) -> str:"""Transcribe a YouTube video."""transcriber = YouTubeTranscriber(api_key)status, transcript = transcriber.process_video(url, api_key)return transcript@register_tool("chat_about_video")async def chat_about_video(transcript: str, question: str, api_key: str) -> str:"""Chat about a transcribed video."""transcriber = YouTubeTranscriber(api_key)8 unmodified lines@app.get("/debug/tools")async def list_tools():"""List available MCP tools"""return {"tools": [t.name for t in tools]}class YouTubeTranscriber:def __init__(self, api_key: str = None):329 unmodified linesdemo.queue()app = gr.mount_gradio_app(app, demo, path="/")# Configure MCPmcp.init(tools=tools)mcp.mount(app, path="/gradio_api/mcp")# Start the serverimport uvicorn2 unmodified lineshost="0.0.0.0",port=7880,log_level="info",reload=True)
app.py+16-17