-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtry.py
More file actions
36 lines (29 loc) · 1.21 KB
/
try.py
File metadata and controls
36 lines (29 loc) · 1.21 KB
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
import vertexai
from vertexai.generative_models import GenerativeModel, Part
import pathlib
import textwrap
import google.generativeai as genai
from IPython.display import display
from IPython.display import Markdown
def generate_text_from_image(project_id: str, location: str)->str:
# Initialize Vertex AI
credentials = service_account.Credentials.from_service_account_file('service_acc_key.json')
vertexai.init(project=project_id, location=location, credentials=credentials)
def to_markdown(text):
text = text.replace('•', ' *')
return Markdown(textwrap.indent(text, '> ', predicate=lambda _: True))
if __name__ == "__main__":
#loading Image
import PIL.Image
img = PIL.Image.open('WechatIMG19.jpg')
#analyzing image
model = genai.GenerativeModel('gemini-pro-vision')
response = model.generate_content(img)
to_markdown(response.text)
response = model.generate_content(
["Write a short, engaging blog post based on this picture. It should include a description of the meal in the photo and talk about my journey meal prepping.", img],
stream=True)
#printing the response
print(response.text)
response.resolve()
to_markdown(response.text)