File size: 2,143 Bytes
927b90e
 
 
 
 
 
 
 
 
5cf934c
927b90e
 
 
 
 
5cf934c
927b90e
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
d535f5a
927b90e
 
 
 
5cf934c
927b90e
 
 
 
 
 
 
5cf934c
 
927b90e
 
5cf934c
d535f5a
 
 
 
 
 
 
 
 
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
import streamlit as st
import tempfile
import os
import google.generativeai as genai

# Configure Google API for audio summarization
GOOGLE_API_KEY = os.getenv("GOOGLE_API_KEY")
genai.configure(api_key=GOOGLE_API_KEY)

def summarize_audio(audio_file_path, prompt):
    """Summarize the audio using Google's Generative API."""
    model = genai.GenerativeModel("models/gemini-1.5-pro-latest")
    audio_file = genai.upload_file(path=audio_file_path)
    response = model.generate_content(
        [
            prompt,
            audio_file
        ]
    )
    return response.text

def save_uploaded_file(uploaded_file):
    """Save uploaded file to a temporary file and return the path."""
    try:
        with tempfile.NamedTemporaryFile(delete=False, suffix='.' + uploaded_file.name.split('.')[-1]) as tmp_file:
            tmp_file.write(uploaded_file.getvalue())
            return tmp_file.name
    except Exception as e:
        st.error(f"Error handling uploaded file: {e}")
        return None

# Streamlit app interface
st.title('Your AI Audio Summarization App')

with st.expander("About Summarization app"):
    st.write("""
        This application utilizes Google's generative AI to summarise the content of audio files. 
        Simply upload your WAV or MP3 file and provide a prompt to receive a brief summary of its contents.
    """)

audio_file = st.file_uploader("Upload Audio File", type=['wav', 'mp3'])
if audio_file is not None:
    audio_path = save_uploaded_file(audio_file)  # Save the uploaded file and get the path
    st.audio(audio_path)

    prompt = st.text_input("Enter your prompt:", "Please summarize the following audio.")

    if st.button('Summarize Audio'):
        with st.spinner('Please Wait : Summarizing...'):
            summary_text = summarize_audio(audio_path, prompt)
            st.info(summary_text)

# Add a section to enter Google API Key
st.sidebar.header("Google API Key")
new_key = st.sidebar.text_input("Enter your Google API Key:", value=GOOGLE_API_KEY)
if new_key:
    os.environ["GOOGLE_API_KEY"] = new_key
    GOOGLE_API_KEY = new_key
    genai.configure(api_key=GOOGLE_API_KEY)