-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.py
44 lines (34 loc) · 1.27 KB
/
app.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
37
38
39
40
41
42
43
44
from dotenv import load_dotenv
load_dotenv() # Initiate the Local Env Variables
from PIL import Image
import google.generativeai as genai
import textwrap
import pathlib
import streamlit as st
# Setup the local environment
import os
genai.configure(api_key = os.getenv("GOOGLE-API-KEY"))
# Create the Streamlit Front End Page
headers = {"authorization": st.secrets["GOOGLE-API-KEY"], "content-type": "application/json"}
st.set_page_config("Gemini APP")
st.header("Image Annotation using Gemini Flash")
input = st.text_input("Input Prompt: ", key = "input")
uploaded_file = st.file_uploader(label = "Upload an Image...", type = ["jpeg", "jpg", "png"])
# Let's define the Model and the Image Annotation
def generate_response(input, image):
model = genai.GenerativeModel("gemini-1.5-flash")
if image != "":
response = model.generate_content([input, image])
else:
response = model.generate_content(input)
return(response.text)
# Image Processing
image = ""
if uploaded_file is not None:
image = Image.open(uploaded_file)
st.image(image, caption = "Image Uploaded", use_column_width = True)
submit = st.button("Do the Magic")
if submit:
response = generate_response(input, image)
st.subheader("Response Generated is ...")
st.write(response)