MeetingUnderstandingDemo / vision_api_call.py
Vlad Bastina
first commit
599e594
import time
from google import genai
import google.generativeai as genai2
import os
class VideoProcessingClient:
def __init__(self, api_key: str, model_name: str = "gemini-1.5-pro-latest"):
"""
Initialize the client with the API key and model name.
"""
self.system_instructions = '''
You are an advanced AI designed to analyze meeting recordings and transcripts to generate detailed reports. Given a video file and its corresponding audio transcript, you will extract key insights and structure them into a comprehensive report.
Your output should include the following sections:
1. Attendance & Attention Analysis
- Identify the attendees present in the meeting.
- Assess their engagement levels based on video cues (e.g., eye contact, posture, participation) and speech patterns (e.g., interruptions, responsiveness).
- Highlight any significant changes in attention throughout the meeting.
2. Meeting Outline
- Provide a structured summary of the meeting, breaking it down into key sections:
- List major topics discussed.
- For each topic, provide a brief one-sentence summary of the key points.
3. Sentiment Analysis
- Perform sentiment analysis on participants based on their speech and facial expressions.
- Indicate the overall emotional tone of the meeting (e.g., positive, neutral, negative).
- Identify any significant emotional moments (e.g., frustration, enthusiasm, agreement).
4. Final Summary
- Give a concise 2-3 sentence conclusion summarizing the meeting's overall tone, engagement, and key takeaways.
Additional Notes:
- Ensure the report is structured, clear, and professional.
- Extract meaningful insights without unnecessary details.
- Use bullet points for clarity where needed.'''
self.api_key = api_key
self.client = genai.Client(api_key=api_key)
genai2.configure(api_key=api_key)
self.model = genai2.GenerativeModel(model_name=model_name,system_instruction=self.system_instructions)
self.video_file = None
def upload_video(self, video_path: str):
"""
Upload a video file and return the file object.
"""
self.video_file = self.client.files.upload(file=video_path)
return self.video_file
def wait_for_processing(self):
"""
Wait for the video file to finish processing.
"""
while self.video_file.state.name == "PROCESSING":
time.sleep(1)
self.video_file = self.client.files.get(name=self.video_file.name)
if self.video_file.state.name == "FAILED":
raise ValueError(f"Video processing failed: {self.video_file.state.name}")
def summarize_video(self,text_transcript:str):
"""
Generate a summary and quiz based on the video.
"""
response = self.model.generate_content([self.video_file.uri,text_transcript],
request_options={"timeout": 600})
return response.text
if __name__ == "__main__":
api_key = "AIzaSyDa-0mHBsJCWI8iRBwCwncNvr3wBOjuEvA"
os.environ['GOOGLE_API_KEY'] = api_key
video_path = "GreatRedSpot.mp4"
prompt = "Summarize this video. Then create a quiz with answer key based on the information in the video."
client = VideoProcessingClient(api_key=api_key)
client.upload_video(video_path)
client.wait_for_processing()
summary_and_quiz = client.summarize_video(prompt)
print("Generated content:\n", summary_and_quiz)