How to Summarize the Text from Audio Using Gemini Pro Multimodal
How to Summarize the Text from Audio Using Gemini Pro Multimodal
Summarize the content material from the Audio file.
In this weblog, we are going to summarize the content material from the audio by harnessing the ability of Gemini Pro Multimodal. Multimodal LLMs can summarize completely different knowledge varieties from massive recordsdata, equivalent to text-to-text and audio-to-text summarization. This Multimodal LLM-powered utility could be very helpful in folks’s day-to-day lives to save lots of time as a substitute of studying or listening to massive quantities of paperwork or recordsdata.
There are many potential areas for this audio-to-text summarization utility,
- Meeting and Conference audio
- Podcast Audio
- News and Media audio
- Journalism (To summarize the interview audio)
- Conversation abstract (for folks with listening to impairments) and so forth.
Gemini Pro 1.5 newest
The Gemini Pro 1.5 is the newest multimodal developed by Google’s Deep Mind. This mannequin is pertinent for a variety of duties and might deal with completely different varieties of knowledge, equivalent to textual content, audio, photos, and video. It additionally has nice problem-solving expertise and might motive throughout 100,000 strains of code.
This mannequin’s context window is up to date from the earlier model and helps as much as 2 million tokens. It is the longest context window of any large-scale basis mannequin. The context window is the dimensions of the token the mannequin takes as enter to generate content material.
The Gemini Pro achieves a near-perfect recall rating on long-context retrieval duties throughout modalities. The mannequin can extra simply course of multimodalities, equivalent to large-scale paperwork, 1000’s of strains of code, hours of audio, video, and extra.
Workflow
In this workflow, two forms of audio recordsdata (WAV & MP3) are used for the summarization job. The audio recordsdata are saved in a brief location as a brief audio file. The momentary audio file path is given to the Gemini mannequin to course of the audio. To summarize the content material, first, the mannequin converts the audio into textual content and generates a abstract by understanding the context of the textual content.
Tutorial
Before writing the code, we have now to generate the Gemini API key from the next hyperlink: https://aistudio.google.com/
You can use VS Code or the Jupyter Notebook textual content editor to jot down code.
The first step on this course of is to put in the required packages.
#necessities.txt
streamlit
python-dotenv
google-generativeai
Then import the mandatory modules from the libraries into the environment.
#import libraries
import streamlit as st
import tempfile
import os
import google.generativeai as genai
from dotenv import load_dotenv
After that, configure the Gemini API key with the environment utilizing the “load_dotenv()” perform. Otherwise, you may instantly use the API key.
load_dotenv()
#Configure Google API
GOOGLE_API_KEY = os.getenv("GOOGLE_API_KEY")
genai.configure(api_key=GOOGLE_API_KEY)
The “summarize_audio” perform was outlined to course of the audio, it’s utilizing the “gemini-1.5-pro-latest” multimodal. This perform takes MP3 or wave file paths as arguments and processes them by the mannequin.
After processing the audio file, it generates the output in textual content type, and you’ll instruct the mannequin based mostly on the specified duties. Here, we instructed the mannequin to “summarize the next audio”.
#perform for summarize the content material from the audio
def summarize_audio(audio_file_path):
"""Summarize the audio utilizing Google's Generative API."""
mannequin = genai.GenerativeMannequin("fashions/gemini-1.5-pro-latest")
audio_file = genai.upload_file(path=audio_file_path)
response = mannequin.generate_content(
[
"Please summarize the following audio.",
audio_file
]
)
return response.textual content
The perform “save_uploaded_file” saves an uploaded file to a brief location on the file system. It creates a brief file with an analogous file extension because the uploaded file, writes the file’s content material to it, and returns the file path.
The besides block is used with the attempt block, it’s used to deal with an sudden error. When an error occurs, the besides block catches the error and permits this system to run as a substitute of crashing.
def save_uploaded_file(uploaded_file):
"""Save uploaded file to a brief file and return the trail."""
attempt:
with tempfile.NamedTemporaryFile(delete=False, suffix='.' + uploaded_file.title.break up('.')[-1]) as tmp_file:
tmp_file.write(uploaded_file.getvalue())
return tmp_file.title
besides Exception as e:
st.error(f"Error dealing with uploaded file: {e}")
return None
The following streamlit codes are used to create a person interface: The “st. title” perform is used to create the title of the web page. The “st. expander” perform is used to create an broaden/collapse container, it shops the details about the applying.
The “st.file_uploader” perform takes an audio file from the customers within the type of ‘WAV’ and ‘MP3’. The above-created two capabilities are built-in with Streamlit to point out the output within the person interface.
# Streamlit app interface
st.title('Audio Summarization App')
with st.expander("About this app"):
st.write("""
This app makes use of Google's Gemini Pro Multimodel to summarize audio recordsdata.
Upload your audio file in WAV or MP3 type and get a concise abstract of its content material.
""")
audio_file = st.file_uploader("Upload Audio File", kind=['wav', 'mp3'])
if audio_file isn't None:
audio_path = save_uploaded_file(audio_file) # Save the uploaded file and get the trail
st.audio(audio_path)
if st.button('Summarize Audio'):
with st.spinner('Summarizing...'):
summary_text = summarize_audio(audio_path)
st.information(summary_text)
To launch the streamlit app, we have now to save lots of your entire code in .py file (app. py). After that, we will use the next command with the trail of the file within the terminal like,
Command: streamlit run app.py
After launching the Python file within the terminal, we are going to see the dashboard within the browser. On this dashboard, I uploaded the Shakespeare’s poem in mp3 type.
After clicking the “Summarize Audio” button, the Gemini Pro Multimodal summarizes the content material from the audio file.
Thanks for Reading!
Check out extra comparable work:
In Plain English 🚀
Thank you for being part of the In Plain English neighborhood! Before you go:
HI-FI News
through Python on Medium https://ift.tt/IXmiLHl
November 8, 2024 at 07:57AM
-
Product on sale
Audiophile Vinyl Records Cleaning BundleOriginal price was: €69.90.€59.90Current price is: €59.90. incl. VAT -
Product on sale
Easy Start Vinyl Records Cleaning KitOriginal price was: €69.90.€59.90Current price is: €59.90. incl. VAT -
Vinyl Records Cleaner Easy Groove Concentrate€34.95 incl. VAT -
Easy Groove Super Set€199.00 incl. VAT -
Easy Groove Enzycaster – vinyl records prewash cleaner€34.95 incl. VAT -
Easy Groove Extreme MK. II- vinyl records prewash cleaner€45.00 incl. VAT -
Vinyl Records Cleaner – Easy Groove Virgin Concentrate€35.00 incl. VAT -
Easy Groove Spray&Wipe vinyl records cleaner€34.95 incl. VAT








