shikharyashmaurya's picture
Create app.py
f376216 verified
raw
history blame
1.32 kB
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")
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)