-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgemini.py
36 lines (26 loc) · 917 Bytes
/
gemini.py
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 streamlit
import google.generativeai as ai
import os
import pathlib
import textwrap
import PIL.Image
# image = PIL.Image.open('meal.png')
# from IPython.display import display
from IPython.display import Markdown
def to_markdown(text):
text = text.replace('•', ' *')
return Markdown(textwrap.indent(text, '> ', predicate=lambda _: True))
ai.configure(api_key="AIzaSyCvhpNhCsZkxnR2bie-RM6U5EcPGJYsYbU")
def create_chat():
model = ai.GenerativeModel('gemini-1.5-flash')
chat = model.start_chat(history=[])
return chat
chat = create_chat()
def gemini_response(input):
response = chat.send_message(input)
return response.text
def gemini_IMGresponse(prompt, img):
model = ai.GenerativeModel('gemini-1.5-flash')
response = model.generate_content([prompt, img], stream=True)
response.resolve()
return response.text