import os from pathlib import Path import PIL.Image import google.generativeai as genai def configure_genai(api_key): genai.configure(api_key=api_key) def generate_content(model, prompt, stream=True): response = model.generate_content(prompt, stream=stream) response.resolve() return response.text def gemini(transcript, question): print(transcript, question) configure_genai(os.environ['GOOGLE_API_KEY']) # Create GenerativeModel instance model = genai.GenerativeModel('gemini-pro') # Generate content using the model and image prompt = [f""" Transcript: ``` {transcript} ``` Provided is a video transcript enclosed within triple backticks. It can be in any language, understand the transcript deeply. Your task is to analyze and understand question deeply and respond to question that is either based on or directly related to the content of the video transcript. Question must be in only english language, if the question is not in english language, please reply with "Please ask questions in english language only. If the question does not pertain to or is not in the context of the video transcript, please reply with "Please ask questions related to the video only." Note: - Do not include `video transcript` in your response, refer it as `video`. - Provide answer in only english language. - Do not hallucionate or provide false information. - Answer must be brief, relevant and concise. Question: {question} """] print("prompt", prompt) response_text = generate_content(model, prompt) return response_text # Optionally display as Markdown