RCaz commited on
Commit
0db6ea0
·
verified ·
1 Parent(s): eb13b82

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +46 -18
app.py CHANGED
@@ -1,34 +1,62 @@
1
  import gradio as gr
2
  from textblob import TextBlob
3
 
4
- def sentiment_analysis(text: str) -> dict:
5
- """
6
- Analyze the sentiment of the given text.
7
 
 
 
8
  Args:
9
- text (str): The text to analyze
10
-
11
  Returns:
12
- dict: A dictionary containing polarity, subjectivity, and assessment
 
13
  """
14
- blob = TextBlob(text)
15
- sentiment = blob.sentiment
16
-
17
- return {
18
- "polarity": round(sentiment.polarity, 2), # -1 (negative) to 1 (positive)
19
- "subjectivity": round(sentiment.subjectivity, 2), # 0 (objective) to 1 (subjective)
20
- "assessment": "positive" if sentiment.polarity > 0 else "negative" if sentiment.polarity < 0 else "neutral"
 
 
 
 
21
  }
 
 
 
 
22
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
23
  # Create the Gradio interface
24
  demo = gr.Interface(
25
- fn=sentiment_analysis,
26
- inputs=gr.Textbox(placeholder="Enter text to analyze..."),
27
  outputs=gr.JSON(),
28
- title="Text Sentiment Analysis",
29
- description="Analyze the sentiment of text using TextBlob"
30
  )
31
 
32
  # Launch the interface and MCP server
33
  if __name__ == "__main__":
34
- demo.launch(mcp_server=True)
 
1
  import gradio as gr
2
  from textblob import TextBlob
3
 
4
+ import yt_dlp
5
+ import os
 
6
 
7
+ def download_video(url, request):
8
+ """downlad video and audio from youtube url
9
  Args:
10
+ url (str): youtube video url
11
+ output_path (str): path to save the downloaded files
12
  Returns:
13
+ video_filename (str): path to the downloaded video file
14
+ audio_filename (str): path to the downloaded audio file
15
  """
16
+
17
+ # instanciate output path
18
+ output_path='./cache'
19
+ if not os.path.exists(output_path):
20
+ os.mkdir(output_path)
21
+
22
+ # get video
23
+ ydl_opts_video = {
24
+ 'format': 'worst[ext=mp4]',
25
+ 'outtmpl': output_path+'/video/'+'%(title)s_video.%(ext)s',
26
+ 'quiet': True
27
  }
28
+ print('Downloading video...')
29
+ with yt_dlp.YoutubeDL(ydl_opts_video) as ydl:
30
+ info_dict = ydl.extract_info(url, download=True)
31
+ video_filename = ydl.prepare_filename(info_dict)
32
 
33
+ # get audio
34
+ audio_opts = {
35
+ 'format': 'bestaudio[ext=m4a]',
36
+ 'outtmpl': output_path+'/audio/'+'%(title)s.audio.%(ext)s',
37
+ 'quiet': False,
38
+ 'noplaylist': True,
39
+ }
40
+ print('Downloading audio...')
41
+ with yt_dlp.YoutubeDL(audio_opts) as ydl:
42
+ info_dict = ydl.extract_info(url, download=True)
43
+ audio_filename = ydl.prepare_filename(info_dict)
44
+
45
+
46
+ return {
47
+ "video_path": video_filename,
48
+ "audio_path": audio_filename,
49
+ "request": request
50
+ }
51
  # Create the Gradio interface
52
  demo = gr.Interface(
53
+ fn=download_video, # will use function arguments to define inputs names
54
+ inputs=[gr.Textbox(placeholder="Enter video url"),gr.Textbox(placeholder="Enter request")],
55
  outputs=gr.JSON(),
56
+ title="Video information request",
57
+ description="Retreive user's request information from a video"
58
  )
59
 
60
  # Launch the interface and MCP server
61
  if __name__ == "__main__":
62
+ demo.launch()