Spaces:
Sleeping
Sleeping
Add Gemini API and Youtube functionality
Browse files
app.py
CHANGED
@@ -1,11 +1,16 @@
|
|
1 |
import streamlit as st
|
2 |
-
from transformers import pipeline
|
3 |
from pytube import YouTube
|
4 |
from pydub import AudioSegment
|
5 |
from audio_extract import extract_audio
|
6 |
-
|
7 |
import os
|
|
|
8 |
|
|
|
|
|
|
|
|
|
9 |
|
10 |
st.set_page_config(
|
11 |
page_title="VidText"
|
@@ -46,20 +51,28 @@ def transcribe_video(processed_audio):
|
|
46 |
text_extract = transcriber_model(processed_audio)
|
47 |
return text_extract['text']
|
48 |
|
49 |
-
|
|
|
|
|
|
|
50 |
# Streamlit UI
|
51 |
|
52 |
-
|
|
|
|
|
53 |
|
54 |
-
|
55 |
-
|
56 |
-
|
57 |
-
|
58 |
-
|
59 |
-
|
60 |
-
|
61 |
-
|
62 |
-
|
|
|
|
|
|
|
63 |
|
64 |
|
65 |
# Video file transcription
|
@@ -74,6 +87,9 @@ with file_select_tab:
|
|
74 |
video_transcript = transcribe_video(audio)
|
75 |
st.success(f"Transcription successful")
|
76 |
st.write(video_transcript)
|
|
|
|
|
|
|
77 |
|
78 |
|
79 |
# Audio transcription
|
@@ -87,3 +103,8 @@ with audio_file_tab:
|
|
87 |
audio_transcript = transcribe_video(processed_audio)
|
88 |
st.success(f"Transcription successful")
|
89 |
st.write(audio_transcript)
|
|
|
|
|
|
|
|
|
|
|
|
1 |
import streamlit as st
|
2 |
+
from transformers import pipeline
|
3 |
from pytube import YouTube
|
4 |
from pydub import AudioSegment
|
5 |
from audio_extract import extract_audio
|
6 |
+
import google.generativeai as google_genai
|
7 |
import os
|
8 |
+
from dotenv import load_dotenv
|
9 |
|
10 |
+
load_dotenv()
|
11 |
+
|
12 |
+
GOOGLE_API_KEY = os.getenv("GOOGLE_API_KEY")
|
13 |
+
google_genai.configure(api_key=GOOGLE_API_KEY)
|
14 |
|
15 |
st.set_page_config(
|
16 |
page_title="VidText"
|
|
|
51 |
text_extract = transcriber_model(processed_audio)
|
52 |
return text_extract['text']
|
53 |
|
54 |
+
def generate_ai_summary(transcript):
|
55 |
+
model = google_genai.GenerativeModel('gemini-pro')
|
56 |
+
model_response = model.generate_content([f"Give a summary of the text {transcript}"], stream=True)
|
57 |
+
return model_response.text
|
58 |
# Streamlit UI
|
59 |
|
60 |
+
youtube_url_tab, file_select_tab, audio_file_tab = st.tabs(
|
61 |
+
["Youtube url", "Video file", "Audio file"]
|
62 |
+
)
|
63 |
|
64 |
+
with youtube_url_tab:
|
65 |
+
url = st.text_input("Enter the Youtube url")
|
66 |
+
yt_video, title = youtube_video_downloader(url)
|
67 |
+
if yt_video:
|
68 |
+
if st.button("Transcribe"):
|
69 |
+
with st.spinner("Transcribing..."):
|
70 |
+
ytvideo_transcript = transcribe_video(yt_video)
|
71 |
+
st.success(f"Transcription successful")
|
72 |
+
st.write(ytvideo_transcript)
|
73 |
+
if st.button("Generate Summary"):
|
74 |
+
summary = generate_ai_summary(ytvideo_transcript)
|
75 |
+
st.write(summary)
|
76 |
|
77 |
|
78 |
# Video file transcription
|
|
|
87 |
video_transcript = transcribe_video(audio)
|
88 |
st.success(f"Transcription successful")
|
89 |
st.write(video_transcript)
|
90 |
+
if st.button("Generate Summary"):
|
91 |
+
summary = generate_ai_summary(video_transcript)
|
92 |
+
st.write(summary)
|
93 |
|
94 |
|
95 |
# Audio transcription
|
|
|
103 |
audio_transcript = transcribe_video(processed_audio)
|
104 |
st.success(f"Transcription successful")
|
105 |
st.write(audio_transcript)
|
106 |
+
|
107 |
+
|
108 |
+
if st.button("Generate Summary"):
|
109 |
+
summary = generate_ai_summary(audio_transcript)
|
110 |
+
st.write(summary)
|