Spaces:
Sleeping
Sleeping
File size: 1,838 Bytes
e2ab9e1 0f62bac e2ab9e1 0f62bac e2ab9e1 0f62bac e2ab9e1 0f62bac e2ab9e1 0f62bac e2ab9e1 0f62bac e2ab9e1 0f62bac e2ab9e1 0f62bac e2ab9e1 0f62bac |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 |
# import gradio as gr
# def add_numbers(a: float, b: float) -> float:
# """
# Adds two numbers together.
# Args:
# a: The first number.
# b: The second number.
# """
# return a + b
# # Create a simple interface for our tool
# iface = gr.Interface(
# fn=add_numbers,
# inputs=[
# gr.Number(label="First Number"),
# gr.Number(label="Second Number")
# ],
# outputs=gr.Number(label="Sum"),
# title="Addition MCP Server",
# description="A simple MCP tool that adds two numbers. [1, 2]"
# )
# # Launch the app as an MCP server. This is the most important part.
# if __name__ == "__main__":
# iface.launch(mcp_server=True)
import gradio as gr
from youtube_transcript_api import YouTubeTranscriptApi
def get_transcript(video_id: str) -> str:
"""
Fetches the transcript for a given YouTube video ID.
Args:
video_id: The unique ID of the YouTube video (e.g., 'dQw4w9WgXcQ').
"""
try:
# Fetch the transcript using the library
transcript_list = YouTubeTranscriptApi.get_transcript(video_id)
# Combine the list of dictionaries into a single string
transcript = " ".join([item['text'] for item in transcript_list])
return transcript
except Exception as e:
# Return an error message if the transcript can't be found
return f"Could not retrieve transcript. Error: {e}"
# Create a simple Gradio interface for our tool
iface = gr.Interface(
fn=get_transcript,
inputs=gr.Textbox(label="YouTube Video ID"),
outputs=gr.Textbox(label="Transcript"),
title="Transcript MCP Server",
description="An MCP tool that fetches a YouTube transcript from a video ID. [1, 2]"
)
# Launch the app as an MCP server
if __name__ == "__main__":
iface.launch(mcp_server=True) |