Spaces:
Sleeping
Sleeping
Update session_analysis.py
Browse files- session_analysis.py +66 -6
session_analysis.py
CHANGED
@@ -1,4 +1,6 @@
|
|
1 |
import streamlit as st
|
|
|
|
|
2 |
import pandas as pd
|
3 |
import plotly.express as px
|
4 |
import plotly.graph_objects as go
|
@@ -64,23 +66,37 @@ def process_media_file(file, type):
|
|
64 |
progress_bar = st.progress(0)
|
65 |
|
66 |
try:
|
67 |
-
#
|
68 |
-
|
69 |
-
status.text(
|
70 |
-
progress_bar.progress(
|
71 |
-
|
|
|
|
|
|
|
|
|
72 |
# Generate transcript
|
73 |
-
transcript
|
|
|
|
|
|
|
|
|
74 |
if transcript:
|
75 |
st.session_state.current_transcript = transcript
|
|
|
|
|
76 |
analyze_session_content(transcript)
|
77 |
|
|
|
|
|
|
|
78 |
except Exception as e:
|
79 |
st.error(f"Error processing file: {str(e)}")
|
80 |
finally:
|
81 |
status.empty()
|
82 |
progress_bar.empty()
|
83 |
|
|
|
84 |
def get_processing_step_name(step):
|
85 |
steps = [
|
86 |
"Loading media file",
|
@@ -207,6 +223,50 @@ def analyze_session_content(content):
|
|
207 |
except Exception as e:
|
208 |
st.error(f"Error during analysis: {str(e)}")
|
209 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
210 |
def process_analysis_results(raw_analysis):
|
211 |
"""Process and structure the analysis results"""
|
212 |
# Parse the raw analysis text and extract structured data
|
|
|
1 |
import streamlit as st
|
2 |
+
from google.cloud import speech_v1
|
3 |
+
import io
|
4 |
import pandas as pd
|
5 |
import plotly.express as px
|
6 |
import plotly.graph_objects as go
|
|
|
66 |
progress_bar = st.progress(0)
|
67 |
|
68 |
try:
|
69 |
+
# Convert file to audio if needed
|
70 |
+
if type == "Video Recording":
|
71 |
+
status.text("Converting video to audio...")
|
72 |
+
progress_bar.progress(20)
|
73 |
+
# Add video to audio conversion here if needed
|
74 |
+
audio_content = convert_video_to_audio(file)
|
75 |
+
else:
|
76 |
+
audio_content = file.read()
|
77 |
+
|
78 |
# Generate transcript
|
79 |
+
status.text("Generating transcript...")
|
80 |
+
progress_bar.progress(60)
|
81 |
+
|
82 |
+
transcript = generate_transcript(audio_content)
|
83 |
+
|
84 |
if transcript:
|
85 |
st.session_state.current_transcript = transcript
|
86 |
+
status.text("Analyzing content...")
|
87 |
+
progress_bar.progress(80)
|
88 |
analyze_session_content(transcript)
|
89 |
|
90 |
+
progress_bar.progress(100)
|
91 |
+
status.text("Processing complete!")
|
92 |
+
|
93 |
except Exception as e:
|
94 |
st.error(f"Error processing file: {str(e)}")
|
95 |
finally:
|
96 |
status.empty()
|
97 |
progress_bar.empty()
|
98 |
|
99 |
+
|
100 |
def get_processing_step_name(step):
|
101 |
steps = [
|
102 |
"Loading media file",
|
|
|
223 |
except Exception as e:
|
224 |
st.error(f"Error during analysis: {str(e)}")
|
225 |
|
226 |
+
|
227 |
+
def generate_transcript(audio_content):
|
228 |
+
"""
|
229 |
+
Generate transcript from audio content using Google Speech-to-Text
|
230 |
+
Note: This requires the Google Cloud Speech-to-Text API
|
231 |
+
"""
|
232 |
+
try:
|
233 |
+
# Initialize Speech-to-Text client
|
234 |
+
client = speech_v1.SpeechClient()
|
235 |
+
|
236 |
+
# Configure audio and recognition settings
|
237 |
+
audio = speech_v1.RecognitionAudio(content=audio_content)
|
238 |
+
config = speech_v1.RecognitionConfig(
|
239 |
+
encoding=speech_v1.RecognitionConfig.AudioEncoding.LINEAR16,
|
240 |
+
sample_rate_hertz=16000,
|
241 |
+
language_code="en-US",
|
242 |
+
enable_automatic_punctuation=True,
|
243 |
+
)
|
244 |
+
|
245 |
+
# Perform the transcription
|
246 |
+
response = client.recognize(config=config, audio=audio)
|
247 |
+
|
248 |
+
# Combine all transcriptions
|
249 |
+
transcript = ""
|
250 |
+
for result in response.results:
|
251 |
+
transcript += result.alternatives[0].transcript + " "
|
252 |
+
|
253 |
+
return transcript.strip()
|
254 |
+
|
255 |
+
except Exception as e:
|
256 |
+
st.error(f"Error in transcript generation: {str(e)}")
|
257 |
+
return None
|
258 |
+
|
259 |
+
def convert_video_to_audio(video_file):
|
260 |
+
"""
|
261 |
+
Convert video file to audio content
|
262 |
+
Note: This is a placeholder - you'll need to implement actual video to audio conversion
|
263 |
+
"""
|
264 |
+
# Placeholder for video to audio conversion
|
265 |
+
# You might want to use libraries like moviepy or ffmpeg-python
|
266 |
+
st.warning("Video to audio conversion not implemented yet")
|
267 |
+
return None
|
268 |
+
|
269 |
+
|
270 |
def process_analysis_results(raw_analysis):
|
271 |
"""Process and structure the analysis results"""
|
272 |
# Parse the raw analysis text and extract structured data
|