cranonieu2021 commited on
Commit
3331caa
1 Parent(s): 4d7ec8c

Update gradio_nlp_group_project.py

Browse files
Files changed (1) hide show
  1. gradio_nlp_group_project.py +16 -16
gradio_nlp_group_project.py CHANGED
@@ -62,27 +62,27 @@ def get_transcript(video_id):
62
  except Exception as e:
63
  return f"An error occurred: {str(e)}", 'en'
64
 
65
- available_languages = []
66
-
67
- for transcript in transcripts:
68
- language_details = {
69
- 'Language': transcript.language,
70
- 'Language Code': transcript.language_code,
71
- 'Is Generated': transcript.is_generated,
72
- 'Is Translatable': transcript.is_translatable
73
- }
74
 
75
  available_languages.append(language_details)
76
 
77
- available_languages = [transcript['Language Code'] for transcript in available_languages if transcript['Language Code'] in ['en']]
78
 
79
- if 'en' in available_languages:
80
- transcript_list = YouTubeTranscriptApi.get_transcript(video_id, languages=['en'])
81
- transcript_text = ' '.join([i['text'] for i in transcript_list])
82
 
83
- return transcript_text, 'en'
84
- else:
85
- return 'Transcript in unsupported language.'
86
 
87
  def process_text(video_id):
88
  transcript, language = get_transcript(video_id)
 
62
  except Exception as e:
63
  return f"An error occurred: {str(e)}", 'en'
64
 
65
+ available_languages = []
66
+
67
+ for transcript in transcripts:
68
+ language_details = {
69
+ 'Language': transcript.language,
70
+ 'Language Code': transcript.language_code,
71
+ 'Is Generated': transcript.is_generated,
72
+ 'Is Translatable': transcript.is_translatable
73
+ }
74
 
75
  available_languages.append(language_details)
76
 
77
+ available_languages = [transcript['Language Code'] for transcript in available_languages if transcript['Language Code'] in ['en']]
78
 
79
+ if 'en' in available_languages:
80
+ transcript_list = YouTubeTranscriptApi.get_transcript(video_id, languages=['en'])
81
+ transcript_text = ' '.join([i['text'] for i in transcript_list])
82
 
83
+ return transcript_text, 'en'
84
+ else:
85
+ return 'Transcript in unsupported language.'
86
 
87
  def process_text(video_id):
88
  transcript, language = get_transcript(video_id)