Badro commited on
Commit
09cb6ce
·
verified ·
1 Parent(s): 104d0ec

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +11 -17
app.py CHANGED
@@ -7,13 +7,12 @@ from textblob import TextBlob
7
  sentiment_analyzer = pipeline("sentiment-analysis")
8
 
9
  def analyze_youtube_content(youtube_url, transcript_text=""):
10
- """Main function to analyze YouTube content"""
11
  results = {}
12
 
13
- # If URL is provided, get video info
14
  if youtube_url:
15
  try:
16
- # Create a YouTube object
17
  yt = pytube.YouTube(youtube_url)
18
  results["video_info"] = {
19
  "title": yt.title,
@@ -25,24 +24,19 @@ def analyze_youtube_content(youtube_url, transcript_text=""):
25
  "message": str(e)
26
  }
27
 
28
- # If transcript is provided, analyze it
29
  if transcript_text:
30
- # Analyze sentiment with TextBlob
31
  blob = TextBlob(transcript_text)
32
- textblob_sentiment = blob.sentiment
33
 
34
- # Analyze sentiment with Hugging Face
35
  hf_result = sentiment_analyzer(transcript_text[:512])[0]
36
 
37
  results["sentiment"] = {
38
- "textblob": {
39
- "polarity": round(textblob_sentiment.polarity, 2),
40
- "assessment": "positive" if textblob_sentiment.polarity > 0 else "negative" if textblob_sentiment.polarity < 0 else "neutral"
41
- },
42
- "huggingface": {
43
- "label": hf_result["label"],
44
- "score": round(hf_result["score"], 4)
45
- }
46
  }
47
 
48
  return results
@@ -59,6 +53,6 @@ demo = gr.Interface(
59
  description="Analyze viral moments from YouTube videos using ML models"
60
  )
61
 
62
- # Launch the app with MCP server enabled
63
  if __name__ == "__main__":
64
- demo.launch(mcp_server=True)
 
7
  sentiment_analyzer = pipeline("sentiment-analysis")
8
 
9
  def analyze_youtube_content(youtube_url, transcript_text=""):
10
+ """Analyze YouTube content"""
11
  results = {}
12
 
13
+ # Get video info
14
  if youtube_url:
15
  try:
 
16
  yt = pytube.YouTube(youtube_url)
17
  results["video_info"] = {
18
  "title": yt.title,
 
24
  "message": str(e)
25
  }
26
 
27
+ # Analyze transcript
28
  if transcript_text:
29
+ # TextBlob sentiment
30
  blob = TextBlob(transcript_text)
31
+ sentiment = blob.sentiment
32
 
33
+ # Hugging Face sentiment
34
  hf_result = sentiment_analyzer(transcript_text[:512])[0]
35
 
36
  results["sentiment"] = {
37
+ "polarity": round(sentiment.polarity, 2),
38
+ "assessment": "positive" if sentiment.polarity > 0 else "negative" if sentiment.polarity < 0 else "neutral",
39
+ "huggingface": hf_result["label"]
 
 
 
 
 
40
  }
41
 
42
  return results
 
53
  description="Analyze viral moments from YouTube videos using ML models"
54
  )
55
 
56
+ # Launch with MCP server enabled
57
  if __name__ == "__main__":
58
+ demo.launch(mcp_server=True)