Analyzing video, audio and PDF information with Gemini and LangChain4j

Analyzing video, audio and PDF information with Gemini and LangChain4j

Certain fashions like Gemini are multimodal.
This implies that they settle for extra than simply textual content as enter.
Some fashions help textual content and pictures, however Gemini goes additional and in addition helps audio, video, and PDF information.
So you’ll be able to combine and match textual content prompts and completely different multimedia information or PDF paperwork.

Until LangChain4j 0.32, the fashions might solely help textual content and pictures,
however since my PR received merged into the newly launched
0.33 model,
you should utilize all these information with the LangChain4j Gemini module!

Let’s take a look!

Getting the transcription of a podcast recording

Are you an avid podcast listener and need to learn its transcription?
Or you need to publish that transcription as show-notes of your individual podcast in your web site?

You can ask Gemini for the transcription with the next code:

var mannequin = VertexAiGeminiChatModel.builder()
 .venture(PROJECT_ID)
 .location(LOCATION)
 .modelName("gemini-1.5-pro")
 .construct();

Response<AiMessage> response = mannequin.generate(
 UserMessage.from(
 AudioContent.from(
 "https://storage.googleapis.com/cloud-samples-data/"
 + "generative-ai/audio/pixel.mp3"),
 TextContent.from(
 "Write a transcription of this audio file")
 )
);

System.out.println(response.content material().textual content());

Above, we created an audio content material object with the AudioContent.from(...) technique.
This technique can take a string which could be a direct URL to a file on the internet,
it may be a Google Cloud Storage URL as properly (like gs://bucket/audio.mp3).
It is feasible to load an area file out of your file system with AudioContent.from(Paths.get("audio.mp3").toUri()).
You may even move the bottom 64 encoded content material of the audio file and specify its mime sort.

What else might you do with audio information?

  • If you’re in a rush and don’t have time to take heed to this one-hour episode,
    as a substitute of asking for the entire transcript, you might change the immediate to ask for a abstract.
    That approach if it’s price spending an hour to take heed to all of it.

  • Gemini additionally accepts a number of audio information in enter, so in case you are recording interviews of individuals on a particular matter,
    you might ask Gemini to distinction the variations in these responses.

Preparing YouTube video chaptering

Let’s say you’re a YouTuber, and also you need to do your individual video chaptering, as a substitute of counting on the the automated chapters.
How are you able to try this?

var mannequin = VertexAiGeminiChatModel.builder()
 .venture(PROJECT_ID)
 .location(LOCATION)
 .modelName("gemini-1.5-flash")
 .construct();

Response<AiMessage> response = mannequin.generate(
 UserMessage.from(
 VideoContent.from(
 "https://storage.googleapis.com/cloud-samples-data/"
 + "generative-ai/video/behind_the_scenes_pixel.mp4"),
 TextContent.from(
 "Prepare chapters for this video file, "
 + "utilizing the YouTube chapter notation")
 )
);

System.out.println(response.content material().textual content());

For this video, the chapters generated look as follows:

00:00 Making a Film with a Blind Director
00:16 Adam Morse, Filmmaker
00:28 The Film Shoot
00:48 A Blind Man & His Girlfriend
01:15 Google Pixel Phone
01:33 Guided Frame
02:06 The Technical Crew
02:32 Visual Effects
02:45 Misconceptions About Blindness
03:20 Filmmaking with a Team
03:46 Google Accessibility
04:00 One Person's Perspective
04:29 Adam's Vision
05:03 A Beautiful Position
05:19 Google Logo

What else might you do with movies?

  • If a video of your assembly or your convention presentation has been recorded,
    you might use this method to ask Gemini for a abstract of the video, to get the assorted sections, to write down the transcript.

  • We typically file movies of our household, our kids, and so forth.
    It’s not all the time straightforward to search by means of these movies.
    You might ask Gemini to supply a abstract of the video,
    that you’d then index with some search engine, or simply do some easy grep search from the command-line.

Asking questions on PDF paperwork

Let’s take a look at one final instance: PDF paperwork.

With LangChain4j, it’s doable to make use of the Apache Tika-based doc loader to get the textual content content material of a PDF.
However, you unfastened some necessary semantic data, because the format could also be necessary,
or the figures could convey as properly some important particulars.

Fortunately, Gemini can ingest PDF paperwork straight, with out an intermediate textual content transcription.

This means that you can ask questions on PDf paperwork, and since Gemini has a really massive context window,
it’s capable of analyze very large paperwork, or a number of paperwork on the identical time,
with out having to implement your individual RAG system (Retrieval Augmented Generation).

var mannequin = VertexAiGeminiChatModel.builder()
 .venture(PROJECT_ID)
 .location(LOCATION)
 .modelName("gemini-1.5-flash")
 .construct();

Response<AiMessage> response = mannequin.generate(
 UserMessage.from(
 PdfFileContent.from(
 "https://proceedings.neurips.cc/paper_files/paper/2017"
 + "/file/3f5ee243547dee91fbd053c1c4a845aa-Paper.pdf"),
 TextContent.from(
 "Give a abstract of this paper")
 )
);

System.out.println(response.content material().textual content());

This instance analyzes the well-known “Attention is all you want” paper that launched the idea of Transformer neural networks:

This paper proposes a novel neural community structure referred to as the
Transformer, which depends completely on an consideration mechanism and
dispenses with recurrence and convolutions. The Transformer
outperforms current fashions on two machine translation duties, WMT
2014 English-to-German and WMT 2014 English-to-French, whereas
requiring considerably much less coaching time. The authors argue that
the Transformer's capability to be taught world dependencies with out
regard to their distance within the enter or output sequences, as properly
as its parallelizable nature, make it a promising method for
sequence modeling and transduction issues. They additionally current an
evaluation of the Transformer's completely different parts and their impact
on efficiency. The paper concludes by discussing potential future
instructions for analysis.

What else might you do with PDF paperwork?

  • You can implement some sensible query answering options over your paperwork.

  • Gemini will help make sense of variations between two variations of your PDF paper.

  • Gemini means that you can ingest a number of information on the identical time,
    so it’s doable to move the PDF of your dishwasher guide,
    similtaneously a tutorial displaying restore it,
    after which ask the LLM to reply a query on repair it.

Summary

Multimodality is a strong characteristic of Gemini,
and now LangChain4j is equiped with the power to ship textual content, pictures, audio information, movies, and PDF paperwork,
probably all on the identical time, to create some revolutionary multimedia integrations.

HI-FI News

by way of Guillaume Laforge https://glaforge.dev/

July 26, 2024 at 09:45AM