File size: 2,071 Bytes
8c6edaa
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
import streamlit as st
import whisper
from pyannote.audio import Pipeline
from pyannote.core import Segment
import pandas as pd
import csv
import os
# Import func_py
from func_py import process_audio

# Streamlit app
st.title("Agent Management System Speaker Diarization and Transcription")

# Authentication token input
auth_token = st.text_input("Enter your Hugging Face auth token:", type="password")

# Audio file upload
audio_file = st.file_uploader("Upload an audio file", type=["wav", "mp3", "m4a"])

# Button to process the file
if st.button("Process Audio") and audio_file and auth_token:
    # Save the uploaded audio file to a temporary directory
    with open("temp_audio.wav", "wb") as f:
        f.write(audio_file.read())
    
    st.write("Processing audio...")
    
    # Process the audio file
    result = process_audio("temp_audio.wav", auth_token)
    
    if result:
        st.write("Processing complete. Here are the results:")
        
        # Convert the results into a DataFrame
        data = {
            "Start Time": [seg.start for seg, spk, sent in result],
            "End Time": [seg.end for seg, spk, sent in result],
            "Speaker": [spk for seg, spk, sent in result],
            "Transcript": [sent for seg, spk, sent in result]
        }
        df = pd.DataFrame(data)
        
        # Display the results as a table
        st.dataframe(df)
        
        # Provide an option to download the results as a CSV
        output_csv = "output.csv"
        try:
            df.to_csv(output_csv, index=False)
            st.success(f"Results successfully saved to {output_csv}")
            
            # Allow the user to download the CSV
            with open(output_csv, "rb") as file:
                st.download_button(label="Download CSV", data=file, file_name="output.csv", mime="text/csv")
        except Exception as e:
            st.error(f"Error saving CSV file: {e}")
    else:
        st.error("No result to print or save.")
else:
    st.info("Please upload an audio file and provide a valid auth token.")