File size: 1,382 Bytes
f376216
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
f655170
 
f376216
 
 
 
 
 
 
 
 
 
 
 
 
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
import streamlit as st
import os
import tempfile

import google.generativeai as genai

secret_key = os.getenv("SECRET_KEY")
genai.configure(api_key=secret_key)

prompt="""you are audio summariser.You will be taking the audio
and summarizing the entire audio and providing the important summary in points
within 250 words. Please provide the summary of the audio given here:  """

st.title("Audio Application")

text=st.text_input("What do you want to know about the audio:")

if text:

    prompt=""".You will be analyse the audio and provide the answers of the question given here:  """+text

audio_file = st.file_uploader("Upload an audio file", type=["mp3", "wav", "ogg"])

def generate_gemini_content(prompt,audio_file):

    with tempfile.NamedTemporaryFile(suffix='.wav', delete=False) as tmp_file:
        tmp_file.write(audio_file.getvalue())
        tmp_file.close()  # close the file

        # model = genai.GenerativeModel("models/gemini-1.5-pro-latest")
        model = genai.GenerativeModel("gemini-1.5-pro-latest")
        your_file = genai.upload_file(tmp_file.name)
        response = model.generate_content([prompt, your_file])
        return response.text

    os.remove(tmp_file.name)


if st.button("Answer or summary"):

    if audio_file:
        summary=generate_gemini_content(prompt,audio_file)
        st.markdown("## Summary:")
        st.write(summary)