Spaces:
Sleeping
Sleeping
cranonieu2021
commited on
Commit
•
4d7ec8c
1
Parent(s):
b85a868
Update gradio_nlp_group_project.py
Browse files- gradio_nlp_group_project.py +20 -15
gradio_nlp_group_project.py
CHANGED
@@ -53,7 +53,14 @@ class TextProcessor:
|
|
53 |
|
54 |
def get_transcript(video_id):
|
55 |
|
56 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
57 |
|
58 |
available_languages = []
|
59 |
|
@@ -79,38 +86,36 @@ def get_transcript(video_id):
|
|
79 |
|
80 |
def process_text(video_id):
|
81 |
transcript, language = get_transcript(video_id)
|
82 |
-
if "
|
83 |
return {"Error": transcript, "Language Detected": "None"}
|
84 |
-
processor = TextProcessor(transcript)
|
85 |
-
|
86 |
-
results = {"Language Detected": language} # Include language in the output for debugging
|
87 |
|
88 |
-
|
|
|
89 |
summarized_text = processor.summarize_text(transcript)
|
90 |
translated_text = processor.translate_text(summarized_text)
|
91 |
classification_result = processor.classify_text(summarized_text)
|
92 |
-
results
|
|
|
93 |
'Summarized Text': summarized_text,
|
94 |
'Translated Text': translated_text,
|
95 |
'Classification Result': classification_result
|
96 |
-
}
|
97 |
-
|
98 |
-
results
|
99 |
|
100 |
return results
|
101 |
-
|
102 |
iface = gr.Interface(
|
103 |
fn=process_text,
|
104 |
inputs=[gr.Textbox(label="YouTube Video ID")],
|
105 |
outputs=[gr.JSON(label="Results")],
|
106 |
title="Text Processing App with YouTube Transcript",
|
107 |
-
description="This app allows you to fetch, summarize, translate, and classify YouTube video transcripts
|
108 |
|
109 |
)
|
110 |
|
111 |
def main():
|
112 |
-
|
113 |
-
iface.launch()
|
114 |
|
115 |
if __name__ == '__main__':
|
116 |
-
|
|
|
53 |
|
54 |
def get_transcript(video_id):
|
55 |
|
56 |
+
try:
|
57 |
+
transcripts = YouTubeTranscriptApi.list_transcripts(video_id)
|
58 |
+
except NoTranscriptFound:
|
59 |
+
return "No transcript found for this video.", 'en'
|
60 |
+
except TranscriptsDisabled:
|
61 |
+
return "Transcripts are disabled for this video.", 'en'
|
62 |
+
except Exception as e:
|
63 |
+
return f"An error occurred: {str(e)}", 'en'
|
64 |
|
65 |
available_languages = []
|
66 |
|
|
|
86 |
|
87 |
def process_text(video_id):
|
88 |
transcript, language = get_transcript(video_id)
|
89 |
+
if transcript.startswith("An error occurred:") or "No transcript" in transcript:
|
90 |
return {"Error": transcript, "Language Detected": "None"}
|
|
|
|
|
|
|
91 |
|
92 |
+
processor = TextProcessor(transcript)
|
93 |
+
try:
|
94 |
summarized_text = processor.summarize_text(transcript)
|
95 |
translated_text = processor.translate_text(summarized_text)
|
96 |
classification_result = processor.classify_text(summarized_text)
|
97 |
+
results = {
|
98 |
+
'Language Detected': language,
|
99 |
'Summarized Text': summarized_text,
|
100 |
'Translated Text': translated_text,
|
101 |
'Classification Result': classification_result
|
102 |
+
}
|
103 |
+
except Exception as e:
|
104 |
+
results = {'Error': f"An error occurred during processing: {str(e)}"}
|
105 |
|
106 |
return results
|
107 |
+
|
108 |
iface = gr.Interface(
|
109 |
fn=process_text,
|
110 |
inputs=[gr.Textbox(label="YouTube Video ID")],
|
111 |
outputs=[gr.JSON(label="Results")],
|
112 |
title="Text Processing App with YouTube Transcript",
|
113 |
+
description="This app allows you to fetch, summarize, translate, and classify YouTube video transcripts. Errors are handled and displayed."
|
114 |
|
115 |
)
|
116 |
|
117 |
def main():
|
118 |
+
iface.launch()
|
|
|
119 |
|
120 |
if __name__ == '__main__':
|
121 |
+
main()
|