anurag629 commited on
Commit
62e9276
·
1 Parent(s): 1998817
Files changed (5) hide show
  1. .gitattributes +1 -1
  2. .gitignore +8 -0
  3. aa.py +29 -0
  4. app.py +108 -2
  5. requirements.txt +0 -0
.gitattributes CHANGED
@@ -32,4 +32,4 @@ saved_model/**/* filter=lfs diff=lfs merge=lfs -text
32
  *.xz filter=lfs diff=lfs merge=lfs -text
33
  *.zip filter=lfs diff=lfs merge=lfs -text
34
  *.zst filter=lfs diff=lfs merge=lfs -text
35
- *tfevents* filter=lfs diff=lfs merge=lfs -text
 
32
  *.xz filter=lfs diff=lfs merge=lfs -text
33
  *.zip filter=lfs diff=lfs merge=lfs -text
34
  *.zst filter=lfs diff=lfs merge=lfs -text
35
+ *tfevents* filter=lfs diff=lfs merge=lfs -text
.gitignore ADDED
@@ -0,0 +1,8 @@
 
 
 
 
 
 
 
 
 
1
+ /downloads
2
+
3
+ # Environment
4
+ /.env
5
+ /.venv
6
+
7
+ # git
8
+ /.git
aa.py ADDED
@@ -0,0 +1,29 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from openai import OpenAI
2
+ client = OpenAI(
3
+ api_key="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"
4
+ )
5
+
6
+ response = client.chat.completions.create(
7
+ model="gpt-4o",
8
+ messages=[
9
+ {
10
+ "role": "system",
11
+ "content": [
12
+ {
13
+ "type": "text",
14
+ "text": "Create detailed and formatted markdown notes for the following content:"
15
+ }
16
+ ]
17
+ }
18
+ ],
19
+ response_format={
20
+ "type": "text"
21
+ },
22
+ temperature=1,
23
+ max_tokens=16383,
24
+ top_p=1,
25
+ frequency_penalty=0,
26
+ presence_penalty=0
27
+ )
28
+
29
+ print(response)
app.py CHANGED
@@ -1,4 +1,110 @@
1
  import streamlit as st
 
 
 
 
2
 
3
- x = st.slider('Select a value')
4
- st.write(x, 'squared is', x * x)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  import streamlit as st
2
+ import yt_dlp
3
+ import whisper
4
+ import os
5
+ from openai import OpenAI
6
 
7
+ # App title
8
+ st.title("Youtube Video Summarizer/Notes Maker by Anurag")
9
+
10
+ # Input fields for YouTube video URL and OpenAI API key
11
+ video_url = st.text_input("Enter a valid YouTube video URL:")
12
+ api_key = st.text_input("Enter your OpenAI API Key:", type="password")
13
+
14
+ # Option to choose between formatted markdown notes or summarization
15
+ option = st.radio("Select an option:", ["Create formatted markdown notes", "Summarize video with a given length"])
16
+
17
+ # Input field for summary length if "Summarize" is selected
18
+ summary_length = None
19
+ if option == "Summarize video with a given length":
20
+ summary_length = st.slider("Select summary length (words):", min_value=50, max_value=500, step=50)
21
+
22
+ # Function to download audio using yt-dlp
23
+ def download_audio_with_ytdlp(video_url, output_path="downloads"):
24
+ os.makedirs(output_path, exist_ok=True)
25
+ ydl_opts = {
26
+ 'format': 'bestaudio/best',
27
+ 'outtmpl': f'{output_path}/%(id)s.%(ext)s',
28
+ 'postprocessors': [{
29
+ 'key': 'FFmpegExtractAudio',
30
+ 'preferredcodec': 'mp3',
31
+ 'preferredquality': '192',
32
+ }],
33
+ }
34
+ with yt_dlp.YoutubeDL(ydl_opts) as ydl:
35
+ info_dict = ydl.extract_info(video_url, download=True)
36
+ audio_file = f"{output_path}/{info_dict['id']}.mp3"
37
+ return audio_file
38
+
39
+ # Whisper transcription function
40
+ def transcribe_audio(audio_file):
41
+ model = whisper.load_model("base")
42
+ result = model.transcribe(audio_file)
43
+ return result["text"]
44
+
45
+ # Button to start processing
46
+ if st.button("Generate"):
47
+ if not video_url or not api_key:
48
+ st.error("Please provide both a valid YouTube URL and OpenAI API Key.")
49
+ else:
50
+ try:
51
+ # Download audio using yt-dlp
52
+ st.info("Downloading audio...")
53
+ audio_file = download_audio_with_ytdlp(video_url)
54
+ st.success(f"Audio downloaded successfully! File: {audio_file}")
55
+
56
+ # Transcribe audio using Whisper
57
+ st.info("Transcribing audio...")
58
+ transcript = transcribe_audio(audio_file)
59
+ st.success("Audio transcribed successfully!")
60
+
61
+ # OpenAI API configuration
62
+ client = OpenAI(api_key=api_key)
63
+
64
+ # Prompt based on user selection
65
+ if option == "Create formatted markdown notes":
66
+ system_message = "Generate detailed and well-structured markdown notes from the following transcript."
67
+ else:
68
+ system_message = f"Summarize the following transcript into approximately {summary_length} words."
69
+
70
+ # Call OpenAI chat completion API
71
+ st.info("Processing with OpenAI...")
72
+ try:
73
+ response = client.chat.completions.create(
74
+ model="gpt-4o",
75
+ messages=[
76
+ {
77
+ "role": "system",
78
+ "content": [
79
+ {
80
+ "type": "text",
81
+ "text": system_message
82
+ }
83
+ ]
84
+ },
85
+ {
86
+ "role": "user",
87
+ "content": transcript
88
+ }
89
+ ],
90
+ response_format={
91
+ "type": "text"
92
+ },
93
+ temperature=1,
94
+ max_tokens=16383,
95
+ top_p=1,
96
+ frequency_penalty=0,
97
+ presence_penalty=0
98
+ )
99
+
100
+ # Extract the generated content
101
+ output = response['choices'][0]['message']['content']
102
+ st.success("Output generated successfully!")
103
+ st.text_area("Generated Output:", output, height=300)
104
+
105
+ except Exception as e:
106
+ st.error(f"Error with OpenAI API: {e}")
107
+
108
+
109
+ except Exception as e:
110
+ st.error(f"An error occurred: {e}")
requirements.txt ADDED
File without changes