import streamlit as st from PIL import Image import json import os import tempfile from streamlit_app import ( MalayalamTranscriptionPipeline, analyze_text, save_analysis_to_csv, compare_analyses, print_analysis_summary ) # Function to load Lottie or fallback image def load_lottie(filepath): if os.path.exists(filepath): with open(filepath, "r") as f: return json.load(f) return None def display_lottie_or_image(lottie_data, fallback_image_path, height=200, key=None): try: from streamlit_lottie import st_lottie if lottie_data: st_lottie(lottie_data, height=height, key=key) return except ImportError: pass if os.path.exists(fallback_image_path): img = Image.open(fallback_image_path) st.image(img, width=height) else: st.warning("Animation and fallback image not found.") # Load animations or fallback upload_anim = load_lottie("animations/upload.json") analyze_anim = load_lottie("animations/analyze.json") results_anim = load_lottie("animations/results.json") # Page config st.set_page_config( page_title="Malayalam Audio Analyzer", page_icon="đ¤", layout="wide", initial_sidebar_state="expanded" ) # Custom CSS st.markdown(""" """, unsafe_allow_html=True) # Title st.title("đī¸ Malayalam Audio Intelligence Analyzer") st.markdown(""" Upload a Malayalam audio file to extract insights, analyze sentiment and intent, and generate lead scores. """) # Sidebar info with st.sidebar: st.header("âšī¸ About") st.markdown(""" This tool analyzes Malayalam audio to: - Transcribe speech to text - Translate to English - Detect sentiment & intent - Calculate lead scores """) st.header("đ Supported Formats") st.markdown("MP3, WAV, AAC, M4A, FLAC, OGG, WMA") # File Upload with st.container(): col1, col2 = st.columns([3, 1]) with col1: uploaded_file = st.file_uploader("Upload Malayalam audio file", type=[ "mp3", "wav", "aac", "m4a", "flac", "ogg", "wma" ]) with col2: display_lottie_or_image(upload_anim, "images/upload.png", height=150, key="upload") if uploaded_file is not None: with tempfile.NamedTemporaryFile(delete=False, suffix=os.path.splitext(uploaded_file.name)[1]) as tmp: tmp.write(uploaded_file.read()) tmp_path = tmp.name transcriber = MalayalamTranscriptionPipeline() try: with st.container(): st.subheader("đ Processing Pipeline") col1, col2 = st.columns([3, 1]) with col1: progress_bar = st.progress(0) status_text = st.empty() status_text.markdown("### đ§ Transcribing audio...") progress_bar.progress(20) results = transcriber.transcribe_audio(tmp_path) progress_bar.progress(40) if not results or not results.get("raw_transcription"): st.error("Transcription failed.") else: raw_text = results["raw_transcription"] status_text.markdown("### đ Translating to English...") progress_bar.progress(60) translated = transcriber.translate_to_malayalam(results) ml_text = translated.get("malayalam_translation", "") progress_bar.progress(80) status_text.markdown("### đ Analyzing content...") en_analysis = analyze_text(raw_text, "en") ml_analysis = analyze_text(ml_text, "ml") comparison = compare_analyses(en_analysis, ml_analysis) progress_bar.progress(100) status_text.success("â Analysis completed!") with col2: display_lottie_or_image(analyze_anim, "images/analyze.png", height=200, key="analyze") st.subheader("đ Results Overview") tab1, tab2 = st.tabs(["English Transcription", "Malayalam Translation"]) with tab1: st.markdown(f'
â 85%
đ¯ 78%
đĨ {lead_score}/100