|
import streamlit as st |
|
import requests |
|
import requests |
|
from pytube import YouTube |
|
import os |
|
from twelvelabs.models.task import Task |
|
|
|
|
|
st.title('Video Summary Interface') |
|
|
|
from twelvelabs import TwelveLabs |
|
|
|
client = TwelveLabs(api_key=os.environ.get('TL_API_KEY')) |
|
|
|
|
|
tab1, tab2, tab3, tab4, tab5 = st.tabs(["Project Description", "Video Uploader", "Video Indexer", "Video Prompt", "Unique Value Add"]) |
|
|
|
with tab1: |
|
st.header("Project Description") |
|
st.write("Here you can describe the project in detail.") |
|
image_path = 'data/data_projectflow.png' |
|
|
|
|
|
st.image(image_path, caption='Project Flow Diagram') |
|
|
|
|
|
with tab2: |
|
|
|
|
|
|
|
def download_youtube_video(url): |
|
yt = YouTube(url) |
|
stream = yt.streams.filter(file_extension='mp4').first() |
|
video = stream.download() |
|
return video |
|
|
|
st.title('Video Upload and Processing Interface') |
|
|
|
|
|
|
|
|
|
|
|
|
|
with st.container(): |
|
st.header("Video Input") |
|
video_file = st.file_uploader("Upload a video file", type=["mp4", "avi"]) |
|
youtube_url = st.text_input("Or paste a YouTube URL here:") |
|
|
|
|
|
with st.container(): |
|
st.header("Video Processing") |
|
|
|
if st.button("Process Video"): |
|
if video_file is not None: |
|
video_path = video_file.name |
|
with open(video_path, mode='wb') as f: |
|
f.write(video_file.getbuffer()) |
|
elif youtube_url: |
|
video_path = download_youtube_video(youtube_url) |
|
else: |
|
st.warning("Please upload a video file or enter a YouTube URL.") |
|
st.stop() |
|
|
|
print(f"Uploading {video_path}") |
|
task = client.task.create(index_id="<YOUR_INDEX_ID>", file=video_path, language="en") |
|
st.success(f"Task id={task.id}") |
|
|
|
|
|
def on_task_update(task: Task): |
|
st.write(f"Status={task.status}") |
|
|
|
task.wait_for_done(callback=on_task_update) |
|
|
|
if task.status != "ready": |
|
st.error(f"Indexing failed with status {task.status}") |
|
else: |
|
st.success(f"Uploaded {video_path}. The unique identifier of your video is {task.video_id}.") |
|
|
|
with tab3: |
|
st.header("Video Indexer") |
|
st.write("Information and controls related to the Scrum TruEra Assistants API.") |
|
|
|
|
|
with tab4: |
|
st.header("Video Prompt") |
|
st.write("Information and controls related to the Scrum TruEra Assistants API.") |
|
|
|
|
|
prompt = st.text_input("Enter your prompt:", |
|
"list the top 4 job interview mistakes and how to improve") |
|
|
|
|
|
number = st.slider("Select the number of top mistakes:", min_value=1, max_value=10, value=4) |
|
|
|
|
|
updated_prompt = prompt.replace("4", str(number)) |
|
|
|
|
|
if st.button("Summarize Video"): |
|
BASE_URL = "https://api.twelvelabs.io/v1.2" |
|
api_key = "tlk_3CPMVGM0ZPTKNT2TKQ3Y62TA7ZY9" |
|
data = { |
|
"video_id": "6636cf7fd1cd5a287c957cf5", |
|
"type": "summary", |
|
"prompt": updated_prompt |
|
} |
|
|
|
|
|
response = requests.post(f"{BASE_URL}/summarize", json=data, headers={"x-api-key": api_key}) |
|
|
|
|
|
if response.status_code == 200: |
|
st.text_area("Summary:", response.json()['summary'], height=300) |
|
else: |
|
st.error("Failed to fetch summary: " + response.text) |
|
|
|
|
|
|
|
|
|
|
|
|
|
with tab5: |
|
st.header("Unique Value Add") |
|
st.write("Information and controls related to the Scrum TruEra Assistants API.") |
|
|
|
|