Spaces:
Build error
Build error
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,6 +1,7 @@
|
|
| 1 |
import streamlit as st
|
| 2 |
from transformers import pipeline, AutoTokenizer, AutoModelForSeq2SeqLM
|
| 3 |
import nltk
|
|
|
|
| 4 |
|
| 5 |
# Download NLTK data
|
| 6 |
nltk.download('punkt')
|
|
@@ -12,11 +13,21 @@ captioner = pipeline("image-to-text", model="Salesforce/blip-image-captioning-ba
|
|
| 12 |
tokenizer = AutoTokenizer.from_pretrained("fabiochiu/t5-base-tag-generation")
|
| 13 |
model = AutoModelForSeq2SeqLM.from_pretrained("fabiochiu/t5-base-tag-generation")
|
| 14 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 15 |
# Streamlit app title
|
| 16 |
st.title("Multi-purpose Machine Learning App")
|
| 17 |
|
| 18 |
# Create tabs for different functionalities
|
| 19 |
-
tab1, tab2 = st.tabs(["Image Captioning", "Text Tag Generation"])
|
| 20 |
|
| 21 |
# Image Captioning Tab
|
| 22 |
with tab1:
|
|
@@ -71,4 +82,22 @@ with tab2:
|
|
| 71 |
else:
|
| 72 |
st.warning("Please enter some text to generate tags.")
|
| 73 |
|
| 74 |
-
#
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
import streamlit as st
|
| 2 |
from transformers import pipeline, AutoTokenizer, AutoModelForSeq2SeqLM
|
| 3 |
import nltk
|
| 4 |
+
from youtube_transcript_api import YouTubeTranscriptApi
|
| 5 |
|
| 6 |
# Download NLTK data
|
| 7 |
nltk.download('punkt')
|
|
|
|
| 13 |
tokenizer = AutoTokenizer.from_pretrained("fabiochiu/t5-base-tag-generation")
|
| 14 |
model = AutoModelForSeq2SeqLM.from_pretrained("fabiochiu/t5-base-tag-generation")
|
| 15 |
|
| 16 |
+
# Function to fetch YouTube transcript
|
| 17 |
+
def fetch_transcript(url):
|
| 18 |
+
video_id = url.split('watch?v=')[-1]
|
| 19 |
+
try:
|
| 20 |
+
transcript = YouTubeTranscriptApi.get_transcript(video_id)
|
| 21 |
+
transcript_text = ' '.join([entry['text'] for entry in transcript])
|
| 22 |
+
return transcript_text
|
| 23 |
+
except Exception as e:
|
| 24 |
+
return str(e)
|
| 25 |
+
|
| 26 |
# Streamlit app title
|
| 27 |
st.title("Multi-purpose Machine Learning App")
|
| 28 |
|
| 29 |
# Create tabs for different functionalities
|
| 30 |
+
tab1, tab2, tab3 = st.tabs(["Image Captioning", "Text Tag Generation", "YouTube Transcript"])
|
| 31 |
|
| 32 |
# Image Captioning Tab
|
| 33 |
with tab1:
|
|
|
|
| 82 |
else:
|
| 83 |
st.warning("Please enter some text to generate tags.")
|
| 84 |
|
| 85 |
+
# YouTube Transcript Tab
|
| 86 |
+
with tab3:
|
| 87 |
+
st.header("YouTube Video Transcript Extractor")
|
| 88 |
+
|
| 89 |
+
# Input for YouTube URL
|
| 90 |
+
youtube_url = st.text_input("Enter YouTube URL:")
|
| 91 |
+
|
| 92 |
+
# Button to get transcript
|
| 93 |
+
if st.button("Get Transcript"):
|
| 94 |
+
if youtube_url:
|
| 95 |
+
transcript = fetch_transcript(youtube_url)
|
| 96 |
+
if "error" not in transcript.lower():
|
| 97 |
+
st.success("Transcript successfully fetched!")
|
| 98 |
+
st.text_area("Transcript", transcript, height=300)
|
| 99 |
+
else:
|
| 100 |
+
st.error(f"An error occurred: {transcript}")
|
| 101 |
+
else:
|
| 102 |
+
st.warning("Please enter a URL.")
|
| 103 |
+
|