Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,31 +1,30 @@
|
|
| 1 |
-
|
| 2 |
import streamlit as st
|
| 3 |
-
from
|
| 4 |
from crewai import Agent, Task, Crew
|
| 5 |
from transformers import pipeline
|
| 6 |
import torch
|
| 7 |
-
|
| 8 |
-
# Hugging Face summarizer setup
|
| 9 |
-
summarizer = pipeline("summarization", model="facebook/bart-large-cnn")
|
| 10 |
|
| 11 |
st.title("AI Blog Writer from YouTube")
|
| 12 |
|
| 13 |
-
#
|
| 14 |
-
|
| 15 |
|
| 16 |
-
def
|
| 17 |
-
"""
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
|
|
|
|
|
|
|
| 25 |
|
| 26 |
-
# CrewAI
|
| 27 |
def create_crew_agents(transcript_text):
|
| 28 |
-
research_agent = Agent(name="Research Agent", goal="Extract
|
| 29 |
blog_writer_agent = Agent(name="Blog Writer", goal="Generate blog content.")
|
| 30 |
editor_agent = Agent(name="Editor", goal="Refine blog for clarity.")
|
| 31 |
|
|
@@ -36,17 +35,21 @@ def create_crew_agents(transcript_text):
|
|
| 36 |
crew = Crew(agents=[research_agent, blog_writer_agent, editor_agent], tasks=[research_task, blog_task, editor_task])
|
| 37 |
return crew
|
| 38 |
|
| 39 |
-
#
|
|
|
|
|
|
|
| 40 |
if st.button("Generate Blog"):
|
| 41 |
-
|
| 42 |
-
if video_id:
|
| 43 |
try:
|
| 44 |
-
|
| 45 |
-
|
| 46 |
-
|
| 47 |
-
|
| 48 |
-
|
| 49 |
-
|
|
|
|
|
|
|
|
|
|
| 50 |
crew = create_crew_agents(transcript_text)
|
| 51 |
results = crew.kickoff()
|
| 52 |
st.subheader("Generated Blog")
|
|
@@ -54,3 +57,5 @@ if st.button("Generate Blog"):
|
|
| 54 |
|
| 55 |
except Exception as e:
|
| 56 |
st.error(f"Error: {e}")
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
import streamlit as st
|
| 2 |
+
from pytube import YouTube
|
| 3 |
from crewai import Agent, Task, Crew
|
| 4 |
from transformers import pipeline
|
| 5 |
import torch
|
| 6 |
+
import whisper
|
|
|
|
|
|
|
| 7 |
|
| 8 |
st.title("AI Blog Writer from YouTube")
|
| 9 |
|
| 10 |
+
# Whisper model setup (Base Model for better speed)
|
| 11 |
+
whisper_model = whisper.load_model("base")
|
| 12 |
|
| 13 |
+
def download_audio(video_url):
|
| 14 |
+
"""Downloads audio from the YouTube video."""
|
| 15 |
+
yt = YouTube(video_url)
|
| 16 |
+
audio_stream = yt.streams.filter(only_audio=True).first()
|
| 17 |
+
audio_path = audio_stream.download(filename="audio.mp4")
|
| 18 |
+
return audio_path
|
| 19 |
+
|
| 20 |
+
def transcribe_audio(audio_path):
|
| 21 |
+
"""Transcribes the audio using Whisper AI."""
|
| 22 |
+
transcription = whisper_model.transcribe(audio_path)
|
| 23 |
+
return transcription['text']
|
| 24 |
|
| 25 |
+
# CrewAI Setup
|
| 26 |
def create_crew_agents(transcript_text):
|
| 27 |
+
research_agent = Agent(name="Research Agent", goal="Extract video transcript.")
|
| 28 |
blog_writer_agent = Agent(name="Blog Writer", goal="Generate blog content.")
|
| 29 |
editor_agent = Agent(name="Editor", goal="Refine blog for clarity.")
|
| 30 |
|
|
|
|
| 35 |
crew = Crew(agents=[research_agent, blog_writer_agent, editor_agent], tasks=[research_task, blog_task, editor_task])
|
| 36 |
return crew
|
| 37 |
|
| 38 |
+
# User Input for Video URL
|
| 39 |
+
video_url = st.text_input("Enter YouTube Video URL:")
|
| 40 |
+
|
| 41 |
if st.button("Generate Blog"):
|
| 42 |
+
if video_url:
|
|
|
|
| 43 |
try:
|
| 44 |
+
st.info("Downloading audio...")
|
| 45 |
+
audio_path = download_audio(video_url)
|
| 46 |
+
st.success("Audio downloaded successfully!")
|
| 47 |
+
|
| 48 |
+
st.info("Transcribing audio using Whisper...")
|
| 49 |
+
transcript_text = transcribe_audio(audio_path)
|
| 50 |
+
st.text_area("Transcript Extracted", transcript_text, height=200)
|
| 51 |
+
|
| 52 |
+
# Generate Blog with CrewAI
|
| 53 |
crew = create_crew_agents(transcript_text)
|
| 54 |
results = crew.kickoff()
|
| 55 |
st.subheader("Generated Blog")
|
|
|
|
| 57 |
|
| 58 |
except Exception as e:
|
| 59 |
st.error(f"Error: {e}")
|
| 60 |
+
else:
|
| 61 |
+
st.warning("Please enter a valid YouTube URL.")
|