|
import streamlit as st |
|
from streamlit import session_state as sst |
|
from utils import navigate_to |
|
|
|
from model_inference import rate_video_frames,get_text_from_audio, summarize_from_text |
|
from utils import read_important_frames, extract_audio |
|
|
|
|
|
|
|
SMALL_VIDEO_LIMIT_MB = 35 |
|
LARGE_VIDEO_LIMIT_MB = 50 |
|
|
|
|
|
SMALL_VIDEO_LIMIT_BYTES = SMALL_VIDEO_LIMIT_MB * 1024 * 1024 |
|
LARGE_VIDEO_LIMIT_BYTES = LARGE_VIDEO_LIMIT_MB * 1024 * 1024 |
|
|
|
async def landing_page(): |
|
|
|
uploaded_file = st.file_uploader("Upload a video", |
|
type=["mp4", "avi", "mov"]) |
|
|
|
if uploaded_file is not None: |
|
file_size = uploaded_file.size |
|
|
|
|
|
if file_size > LARGE_VIDEO_LIMIT_BYTES: |
|
st.error(f"File is too large! Max allowed size is {LARGE_VIDEO_LIMIT_MB}MB. Please upload a smaller version of it.") |
|
|
|
else: |
|
|
|
video_bytes = uploaded_file.read() |
|
|
|
|
|
with st.spinner("Getting most important moments from your video."): |
|
|
|
try: |
|
important_frames = read_important_frames(video_bytes, 100) |
|
|
|
st.success(f"Got important moments.") |
|
|
|
|
|
sst["important_frames"] = important_frames |
|
|
|
except Exception as e: |
|
st.write(f"Sorry couldn't extract important frames from this video & can't rate this on movie scale, because of error: {e}") |
|
|
|
|
|
|
|
with st.spinner("Getting audio transcript from your video for summary"): |
|
try: |
|
audio_transcript_bytes = extract_audio(video_bytes) |
|
|
|
st.success(f"Got audio transcript.") |
|
|
|
|
|
sst["audio_transcript"] = audio_transcript_bytes |
|
|
|
except Exception as e: |
|
st.write(f"Sorry couldn't extract audio from this video & can't rate summarize it, because of error: {e}") |
|
|
|
|
|
st.button("Summarize & Analyze Video", |
|
on_click = navigate_to, |
|
args = ("model_inference_page",) |
|
) |
|
|
|
|
|
|
|
async def model_inference_page(): |
|
|
|
|
|
if "important_frames" in sst: |
|
|
|
important_frames = sst["important_frames"] |
|
with st.spinner("Generating Movie Scale rating for your video"): |
|
try: |
|
video_rating_scale = rate_video_frames(important_frames) |
|
except Exception as e: |
|
video_rating_scale = f"Sorry, we couldn't generate rating of your video because of this error: {e} " |
|
|
|
st.toast("Done") |
|
st.header("Movie Scale Rating of Your Video: ", divider = True) |
|
st.write(video_rating_scale) |
|
st.markdown("************************") |
|
|
|
|
|
|
|
if "audio_transcript" in sst: |
|
|
|
with st.spinner("Extracting text from audio file"): |
|
try: |
|
video_summary_text = get_text_from_audio(sst["audio_transcript"]) |
|
except Exception as e: |
|
video_summary_text = f"Sorry, we couldn't extract text from audio of this file because of this error: {e} " |
|
st.toast("Done") |
|
|
|
if video_summary_text[:5] != "Sorry": |
|
with st.spinner("Summarizing text from entire transcript"): |
|
try: |
|
video_summary_text = summarize_from_text(video_summary_text) |
|
except Exception as e: |
|
video_summary_text = f"Sorry, we couldn't summarize text from audio of this file because of this error: {e} " |
|
st.toast("Done") |
|
|
|
st.header("Audio Transcript summary of your video: ", divider = True) |
|
st.write(video_summary_text) |
|
|
|
|
|
st.button("Go Home", |
|
on_click = navigate_to, |
|
args = ("landing_page",) |
|
) |
|
|
|
|
|
|
|
|