videoChat / lib /services /gemini.py
ns-devel
Added about and sample questions
0f465e7
raw
history blame
1.23 kB
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. Your task is to respond to questions that are either based on or directly related to the content of the video transcript. 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`.
Question: {question}
"""]
print("prompt", prompt)
response_text = generate_content(model, prompt)
return response_text
# Optionally display as Markdown