shreyasiv commited on
Commit
6fa5743
1 Parent(s): 7369d00

Upload 2 files

Browse files
Files changed (2) hide show
  1. app.py +91 -0
  2. requirements.txt +82 -0
app.py ADDED
@@ -0,0 +1,91 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ import openai
3
+ from pytube import YouTube
4
+ import os
5
+ from pathlib import Path
6
+ import shutil
7
+ import whisper
8
+ from dotenv import load_dotenv
9
+ from zipfile import ZipFile
10
+
11
+ load_dotenv()
12
+
13
+ openai.api_key = os.getenv("OPENAI_API_KEY")
14
+
15
+ @st.cache_data
16
+ def load_model():
17
+ model = whisper.load_model("base")
18
+ return model
19
+
20
+ def save_audio(url):
21
+ yt = YouTube(url)
22
+ video = yt.streams.filter(only_audio=True).first()
23
+ out_file = video.download()
24
+ base, ext = os.path.splitext(out_file)
25
+ file_name = base + '.mp3'
26
+ try:
27
+ os.rename(out_file, file_name)
28
+ except WindowsError:
29
+ os.remove(file_name)
30
+ os.rename(out_file, file_name)
31
+ audio_filename = Path(file_name).stem+'.mp3'
32
+ print(yt.title + " Has been successfully downloaded")
33
+ print(file_name)
34
+ return yt.title, audio_filename
35
+
36
+ def audio_to_transcript(audio_file):
37
+ model = load_model()
38
+ result = model.transcribe(audio_file)
39
+ transcript = result["text"]
40
+ return transcript
41
+
42
+ def text_to_news_article(text):
43
+ response = openai.Completion.create(
44
+ model="text-davinci-003",
45
+ prompt="Write a news article in 500 words from the below text:\n"+text,
46
+ temperature=0.7,
47
+ max_tokens=600,
48
+ top_p=1,
49
+ frequency_penalty=0,
50
+ presence_penalty=0
51
+ )
52
+ return response['choices'][0]['text']
53
+
54
+
55
+ st.markdown('# 📝 **News Article Generator App**')
56
+
57
+ st.header('Input the Video URL')
58
+
59
+ url_link = st.text_input('Enter URL of YouTube video:')
60
+
61
+ if st.checkbox('Start Analysis'):
62
+ video_title, audio_filename = save_audio(url_link)
63
+ st.audio(audio_filename)
64
+ transcript = audio_to_transcript(audio_filename)
65
+ st.header("Transcript are getting generated...")
66
+ st.success(transcript)
67
+ st.header("News Article")
68
+ result = text_to_news_article(transcript)
69
+ st.success(result)
70
+
71
+ #save the files
72
+ transcript_txt = open('transcript.txt', 'w')
73
+ transcript_txt.write(transcript)
74
+ transcript_txt.close()
75
+
76
+ article_txt = open('article.txt', 'w')
77
+ article_txt.write(result)
78
+ article_txt.close()
79
+
80
+ zip_file = ZipFile('output.zip', 'w')
81
+ zip_file.write('transcript.txt')
82
+ zip_file.write('article.txt')
83
+ zip_file.close()
84
+
85
+ with open("output.zip", "rb") as zip_download:
86
+ btn = st.download_button(
87
+ label="Download ZIP",
88
+ data=zip_download,
89
+ file_name="output.zip",
90
+ mime="application/zip"
91
+ )
requirements.txt ADDED
@@ -0,0 +1,82 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ aiohttp==3.8.5
2
+ aiosignal==1.3.1
3
+ altair==5.1.2
4
+ async-timeout==4.0.3
5
+ attrs==23.1.0
6
+ blinker==1.6.2
7
+ cachetools==5.3.1
8
+ certifi==2023.7.22
9
+ charset-normalizer==3.3.0
10
+ click==8.1.7
11
+ cmake==3.27.6
12
+ filelock==3.12.4
13
+ frozenlist==1.4.0
14
+ gitdb==4.0.10
15
+ GitPython==3.1.37
16
+ idna==3.4
17
+ importlib-metadata==6.8.0
18
+ Jinja2==3.1.2
19
+ jsonschema==4.19.1
20
+ jsonschema-specifications==2023.7.1
21
+ lit==17.0.2
22
+ llvmlite==0.41.0
23
+ markdown-it-py==3.0.0
24
+ MarkupSafe==2.1.3
25
+ mdurl==0.1.2
26
+ more-itertools==10.1.0
27
+ mpmath==1.3.0
28
+ multidict==6.0.4
29
+ networkx==3.1
30
+ numba==0.58.0
31
+ numpy==1.25.2
32
+ nvidia-cublas-cu11==11.10.3.66
33
+ nvidia-cuda-cupti-cu11==11.7.101
34
+ nvidia-cuda-nvrtc-cu11==11.7.99
35
+ nvidia-cuda-runtime-cu11==11.7.99
36
+ nvidia-cudnn-cu11==8.5.0.96
37
+ nvidia-cufft-cu11==10.9.0.58
38
+ nvidia-curand-cu11==10.2.10.91
39
+ nvidia-cusolver-cu11==11.4.0.1
40
+ nvidia-cusparse-cu11==11.7.4.91
41
+ nvidia-nccl-cu11==2.14.3
42
+ nvidia-nvtx-cu11==11.7.91
43
+ openai==0.28.1
44
+ openai-whisper @ git+https://github.com/openai/whisper.git@0a60fcaa9b86748389a656aa013c416030287d47
45
+ packaging==23.2
46
+ pandas==2.1.1
47
+ Pillow==10.0.1
48
+ protobuf==4.24.4
49
+ pyarrow==13.0.0
50
+ pydeck==0.8.1b0
51
+ pydub==0.25.1
52
+ Pygments==2.16.1
53
+ python-dateutil==2.8.2
54
+ python-dotenv==1.0.0
55
+ pytube==15.0.0
56
+ pytz==2023.3.post1
57
+ referencing==0.30.2
58
+ regex==2023.10.3
59
+ requests==2.31.0
60
+ rich==13.6.0
61
+ rpds-py==0.10.3
62
+ six==1.16.0
63
+ smmap==5.0.1
64
+ streamlit==1.27.2
65
+ sympy==1.12
66
+ tenacity==8.2.3
67
+ tiktoken==0.3.3
68
+ toml==0.10.2
69
+ toolz==0.12.0
70
+ torch==2.0.1
71
+ tornado==6.3.3
72
+ tqdm==4.66.1
73
+ triton==2.0.0
74
+ typing_extensions==4.8.0
75
+ tzdata==2023.3
76
+ tzlocal==5.1
77
+ urllib3==2.0.6
78
+ validators==0.22.0
79
+ watchdog==3.0.0
80
+ whisper==1.1.10
81
+ yarl==1.9.2
82
+ zipp==3.17.0