Spaces:
Sleeping
Sleeping
Refactor accent analysis result display; streamline code structure and improve readability in Streamlit app
Browse files- src/streamlit_app.py +35 -36
src/streamlit_app.py
CHANGED
@@ -681,7 +681,6 @@ with tab1:
|
|
681 |
|
682 |
# Create columns for results
|
683 |
col1, col2 = st.columns([2, 1])
|
684 |
-
|
685 |
with col1:
|
686 |
st.subheader("Accent Analysis Results")
|
687 |
st.markdown(f"**Detected Accent:** {results['accent']}")
|
@@ -691,26 +690,26 @@ with tab1:
|
|
691 |
# Show explanation in a box
|
692 |
st.markdown("### Expert Analysis")
|
693 |
st.info(results['explanation'])
|
694 |
-
|
|
|
695 |
if results['audio_viz']:
|
696 |
try:
|
697 |
st.pyplot(results['audio_viz'])
|
698 |
except Exception as viz_error:
|
699 |
st.warning("Could not display visualization due to torchvision issue.")
|
700 |
-
st.info("Audio analysis was successful even though visualization failed.")
|
701 |
-
|
702 |
-
# Show audio playback
|
703 |
st.audio(audio_path)
|
704 |
-
|
705 |
-
|
706 |
-
|
707 |
-
|
708 |
-
|
709 |
-
|
710 |
-
|
711 |
-
|
712 |
-
|
713 |
-
|
|
|
714 |
|
715 |
except Exception as e:
|
716 |
st.error(f"Error during analysis: {str(e)}")
|
@@ -772,31 +771,31 @@ with tab2:
|
|
772 |
|
773 |
progress_bar.progress(50, text="Analyzing audio...")
|
774 |
|
775 |
-
# Process using the saved file path directly
|
776 |
-
results = process_uploaded_audio(temp_file_path)
|
777 |
|
778 |
progress_bar.progress(100, text="Analysis complete!")
|
779 |
# Display results
|
780 |
st.success("✅ Analysis Complete!")
|
781 |
-
|
782 |
-
|
783 |
-
|
784 |
-
|
785 |
-
|
786 |
-
|
787 |
-
|
788 |
-
|
789 |
-
|
790 |
-
|
791 |
-
|
792 |
-
|
793 |
-
|
794 |
-
|
795 |
-
|
796 |
-
|
797 |
-
|
798 |
-
|
799 |
-
|
|
|
800 |
|
801 |
except subprocess.CalledProcessError as e:
|
802 |
st.error("Error processing audio file")
|
|
|
681 |
|
682 |
# Create columns for results
|
683 |
col1, col2 = st.columns([2, 1])
|
|
|
684 |
with col1:
|
685 |
st.subheader("Accent Analysis Results")
|
686 |
st.markdown(f"**Detected Accent:** {results['accent']}")
|
|
|
690 |
# Show explanation in a box
|
691 |
st.markdown("### Expert Analysis")
|
692 |
st.info(results['explanation'])
|
693 |
+
|
694 |
+
with col2:
|
695 |
if results['audio_viz']:
|
696 |
try:
|
697 |
st.pyplot(results['audio_viz'])
|
698 |
except Exception as viz_error:
|
699 |
st.warning("Could not display visualization due to torchvision issue.")
|
700 |
+
st.info("Audio analysis was successful even though visualization failed.") # Show audio playback
|
|
|
|
|
701 |
st.audio(audio_path)
|
702 |
+
|
703 |
+
# Clean up files
|
704 |
+
try:
|
705 |
+
if os.path.exists(video_path):
|
706 |
+
os.remove(video_path)
|
707 |
+
if os.path.exists(audio_path):
|
708 |
+
os.remove(audio_path)
|
709 |
+
if cookies_file and os.path.exists(cookies_file):
|
710 |
+
os.remove(cookies_file)
|
711 |
+
except Exception as e:
|
712 |
+
st.warning(f"Couldn't clean up temporary files: {str(e)}")
|
713 |
|
714 |
except Exception as e:
|
715 |
st.error(f"Error during analysis: {str(e)}")
|
|
|
771 |
|
772 |
progress_bar.progress(50, text="Analyzing audio...")
|
773 |
|
774 |
+
# Process using the saved file path directly results = process_uploaded_audio(temp_file_path)
|
|
|
775 |
|
776 |
progress_bar.progress(100, text="Analysis complete!")
|
777 |
# Display results
|
778 |
st.success("✅ Analysis Complete!")
|
779 |
+
|
780 |
+
# Create columns for results
|
781 |
+
col1, col2 = st.columns([2, 1])
|
782 |
+
|
783 |
+
with col1:
|
784 |
+
st.subheader("Accent Analysis Results")
|
785 |
+
st.markdown(f"**Detected Accent:** {results['accent']}")
|
786 |
+
st.markdown(f"**English Proficiency:** {results['english_confidence']:.1f}%")
|
787 |
+
st.markdown(f"**Accent Confidence:** {results['accent_confidence']:.1f}%")
|
788 |
+
|
789 |
+
# Show explanation in a box
|
790 |
+
st.markdown("### Expert Analysis")
|
791 |
+
st.info(results['explanation'])
|
792 |
+
with col2:
|
793 |
+
if results['audio_viz']:
|
794 |
+
try:
|
795 |
+
st.pyplot(results['audio_viz'])
|
796 |
+
except Exception as viz_error:
|
797 |
+
st.warning("Could not display visualization due to torchvision issue.")
|
798 |
+
st.info("Audio analysis was successful even though visualization failed.")
|
799 |
|
800 |
except subprocess.CalledProcessError as e:
|
801 |
st.error("Error processing audio file")
|