Spaces:
Sleeping
Sleeping
Update app.py
Browse files
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 |
-
"""
|
| 11 |
results = {}
|
| 12 |
|
| 13 |
-
#
|
| 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 |
-
#
|
| 29 |
if transcript_text:
|
| 30 |
-
#
|
| 31 |
blob = TextBlob(transcript_text)
|
| 32 |
-
|
| 33 |
|
| 34 |
-
#
|
| 35 |
hf_result = sentiment_analyzer(transcript_text[:512])[0]
|
| 36 |
|
| 37 |
results["sentiment"] = {
|
| 38 |
-
"
|
| 39 |
-
|
| 40 |
-
|
| 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
|
| 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)
|