AdWeeb commited on
Commit
4b3f952
1 Parent(s): 013bade

Upload app.py

Browse files
Files changed (1) hide show
  1. app.py +85 -0
app.py ADDED
@@ -0,0 +1,85 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # -*- coding: utf-8 -*-
2
+ """
3
+ Created on Mon Mar 28 01:04:50 2022
4
+
5
+ @author: adeep
6
+ """
7
+ from fnmatch import translate
8
+ import cv2 as cv
9
+ import tempfile
10
+ import numpy as np
11
+ import pandas as pd
12
+ import streamlit as st
13
+ import joblib
14
+ import os
15
+ from moviepy.editor import VideoFileClip
16
+ import speech_recognition as sr
17
+ from pydub import AudioSegment
18
+ from pydub.silence import split_on_silence
19
+ import transformers
20
+ from transformers import pipeline
21
+ import nltk
22
+ nltk.download('punkt')
23
+ nltk.download('averaged_perceptron_tagger')
24
+ import nltk
25
+ nltk.download('punkt')
26
+ nltk.download('averaged_perceptron_tagger')
27
+ from nltk.tokenize import sent_tokenize
28
+ import re
29
+ from utils import get_translation, welcome, get_large_audio_transcription
30
+
31
+ from PIL import Image
32
+
33
+
34
+ def main():
35
+
36
+
37
+ st.title("Summarize Text")
38
+ video = st.file_uploader("Choose a file", type=['mp4'])
39
+ button = st.button("Summarize")
40
+
41
+ max = st.sidebar.slider('Select max', 50, 500, step=10, value=150)
42
+ min = st.sidebar.slider('Select min', 10, 450, step=10, value=50)
43
+
44
+ with st.spinner("Generating Summary.."):
45
+
46
+ if button and video:
47
+ tfile = tempfile.NamedTemporaryFile(delete=False)
48
+ tfile.write(video.read())
49
+ #st.write(tfile.name)
50
+ v = VideoFileClip(tfile.name)
51
+ v.audio.write_audiofile("movie.wav")
52
+ #st.video(video, format="video/mp4", start_time=0)
53
+ st.audio("movie.wav")
54
+ whole_text=get_large_audio_transcription("movie.wav")
55
+ #st.write(whole_text)
56
+ #summarizer = pipeline("summarization")
57
+ summarizer = pipeline("summarization", model="t5-base", tokenizer="t5-base", framework="pt")
58
+ summarized = summarizer(whole_text, min_length=75, max_length=400)
59
+ summ=summarized[0]['summary_text']
60
+ st.write(summ)
61
+
62
+ if 'summary' not in st.session_state:
63
+ st.session_state.summary=True
64
+ st.session_state.summarization = summ
65
+
66
+
67
+ translate = st.sidebar.radio('Do you want to translate the text to any different language?', ('No', 'Yes'))
68
+
69
+ if translate == 'Yes':
70
+ lang_list = ['Hindi', 'Marathi', 'Malayalam', 'Kannada', 'Telugu', 'Tamil', 'Oriya', 'Bengali', 'Gujarati', 'Urdu']
71
+
72
+ s_type = st.sidebar.selectbox('Select the Language in which you want to Translate:',lang_list)
73
+ st.sidebar.write('You selected:', s_type)
74
+
75
+ if 'summary' in st.session_state:
76
+ summarized_text = st.session_state.summarization
77
+ st.write(summarized_text)
78
+ translation = get_translation(source='English', dest=s_type, text=summarized_text)
79
+
80
+ st.sidebar.write(translation)
81
+
82
+
83
+ if __name__ == '__main__':
84
+
85
+ main()