Spaces:
Sleeping
Sleeping
shikharyashmaurya
commited on
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,43 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import streamlit as st
|
2 |
+
import os
|
3 |
+
import tempfile
|
4 |
+
|
5 |
+
import google.generativeai as genai
|
6 |
+
|
7 |
+
secret_key = os.getenv("SECRET_KEY")
|
8 |
+
genai.configure(api_key=secret_key)
|
9 |
+
|
10 |
+
prompt="""you are audio summariser.You will be taking the audio
|
11 |
+
and summarizing the entire audio and providing the important summary in points
|
12 |
+
within 250 words. Please provide the summary of the audio given here: """
|
13 |
+
|
14 |
+
st.title("Audio Application")
|
15 |
+
|
16 |
+
text=st.text_input("What do you want to know about the audio:")
|
17 |
+
|
18 |
+
if text:
|
19 |
+
|
20 |
+
prompt=""".You will be analyse the audio and provide the answers of the question given here: """+text
|
21 |
+
|
22 |
+
audio_file = st.file_uploader("Upload an audio file", type=["mp3", "wav", "ogg"])
|
23 |
+
|
24 |
+
def generate_gemini_content(prompt,audio_file):
|
25 |
+
|
26 |
+
with tempfile.NamedTemporaryFile(suffix='.wav', delete=False) as tmp_file:
|
27 |
+
tmp_file.write(audio_file.getvalue())
|
28 |
+
tmp_file.close() # close the file
|
29 |
+
|
30 |
+
model = genai.GenerativeModel("models/gemini-1.5-pro-latest")
|
31 |
+
your_file = genai.upload_file(tmp_file.name)
|
32 |
+
response = model.generate_content([prompt, your_file])
|
33 |
+
return response.text
|
34 |
+
|
35 |
+
os.remove(tmp_file.name)
|
36 |
+
|
37 |
+
|
38 |
+
if st.button("Answer or summary"):
|
39 |
+
|
40 |
+
if audio_file:
|
41 |
+
summary=generate_gemini_content(prompt,audio_file)
|
42 |
+
st.markdown("## Summary:")
|
43 |
+
st.write(summary)
|