Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -156,31 +156,52 @@ def analyze_sentiment(text):
|
|
| 156 |
sentiment_scores = sid.polarity_scores(text)
|
| 157 |
return sentiment_scores
|
| 158 |
|
| 159 |
-
def main():
|
| 160 |
-
|
| 161 |
-
|
| 162 |
-
|
| 163 |
-
|
| 164 |
-
|
| 165 |
-
|
| 166 |
|
| 167 |
-
|
| 168 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 169 |
try:
|
|
|
|
| 170 |
transcript = get_youtube_transcript(video_url)
|
| 171 |
-
|
| 172 |
-
|
| 173 |
-
print("Summarizing transcript...")
|
| 174 |
summary = summarize_text(transcript)
|
| 175 |
-
|
| 176 |
-
|
| 177 |
-
print("Analyzing sentiment...")
|
| 178 |
sentiment = analyze_sentiment(transcript)
|
| 179 |
-
|
| 180 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 181 |
except Exception as e:
|
| 182 |
-
|
| 183 |
-
|
|
|
|
| 184 |
|
| 185 |
|
| 186 |
def get_recommendations(keywords, max_results=5):
|
|
@@ -340,10 +361,10 @@ with gr.Blocks(theme=gr.themes.Soft()) as app:
|
|
| 340 |
nav_youtube.click(lambda: show_page(youtube_page), outputs=list(show_page(youtube_page).keys()))
|
| 341 |
|
| 342 |
analyze_btn.click(
|
| 343 |
-
|
| 344 |
-
|
| 345 |
-
|
| 346 |
-
|
| 347 |
|
| 348 |
logout_btn.click(
|
| 349 |
lambda: {
|
|
|
|
| 156 |
sentiment_scores = sid.polarity_scores(text)
|
| 157 |
return sentiment_scores
|
| 158 |
|
| 159 |
+
# def main():
|
| 160 |
+
# # Check if a URL is passed as a command-line argument
|
| 161 |
+
# if len(sys.argv) > 1:
|
| 162 |
+
# video_url = sys.argv[1]
|
| 163 |
+
# else:
|
| 164 |
+
# # Use a hardcoded URL for testing if no input is provided
|
| 165 |
+
# video_url = "https://www.youtube.com/watch?v=dQw4w9WgXcQ" # Replace with a valid URL
|
| 166 |
|
| 167 |
+
# print("Fetching transcript...")
|
| 168 |
|
| 169 |
+
# try:
|
| 170 |
+
# transcript = get_youtube_transcript(video_url)
|
| 171 |
+
# print("Transcript fetched successfully.")
|
| 172 |
+
|
| 173 |
+
# print("Summarizing transcript...")
|
| 174 |
+
# summary = summarize_text(transcript)
|
| 175 |
+
# print("Summary:\n", summary)
|
| 176 |
+
|
| 177 |
+
# print("Analyzing sentiment...")
|
| 178 |
+
# sentiment = analyze_sentiment(transcript)
|
| 179 |
+
# print("Sentiment Analysis:\n", sentiment)
|
| 180 |
+
|
| 181 |
+
# except Exception as e:
|
| 182 |
+
# print("An error occurred:", str(e))
|
| 183 |
+
|
| 184 |
+
def process_youtube_video(video_url, keywords):
|
| 185 |
+
"""Process YouTube video URL and keywords for analysis."""
|
| 186 |
try:
|
| 187 |
+
# Fetch transcript
|
| 188 |
transcript = get_youtube_transcript(video_url)
|
| 189 |
+
|
| 190 |
+
# Summarize transcript
|
|
|
|
| 191 |
summary = summarize_text(transcript)
|
| 192 |
+
|
| 193 |
+
# Perform sentiment analysis
|
|
|
|
| 194 |
sentiment = analyze_sentiment(transcript)
|
| 195 |
+
|
| 196 |
+
# Generate recommendations
|
| 197 |
+
recommendations = get_recommendations(keywords)
|
| 198 |
+
|
| 199 |
+
# Return results
|
| 200 |
+
return None, summary, sentiment, recommendations
|
| 201 |
except Exception as e:
|
| 202 |
+
# Handle errors and return them in the output fields
|
| 203 |
+
error_message = f"Error: {str(e)}"
|
| 204 |
+
return None, error_message, error_message, error_message
|
| 205 |
|
| 206 |
|
| 207 |
def get_recommendations(keywords, max_results=5):
|
|
|
|
| 361 |
nav_youtube.click(lambda: show_page(youtube_page), outputs=list(show_page(youtube_page).keys()))
|
| 362 |
|
| 363 |
analyze_btn.click(
|
| 364 |
+
process_youtube_video,
|
| 365 |
+
inputs=[video_url, keywords],
|
| 366 |
+
outputs=[video_thumbnail, summary, sentiment, recommendations]
|
| 367 |
+
)
|
| 368 |
|
| 369 |
logout_btn.click(
|
| 370 |
lambda: {
|