File size: 1,614 Bytes
8677234
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2571aec
8677234
 
 
2571aec
 
 
 
8677234
 
0f465e7
8677234
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
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