Navneetkumar11 commited on
Commit
e2ab9e1
·
verified ·
1 Parent(s): 1ec4892

Update app.py

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