-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.py
64 lines (53 loc) · 1.94 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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
import streamlit as st
from dotenv import load_dotenv
import os
import google.generativeai as genai
import PIL.Image
load_dotenv()
GOOGLE_API_KEY = os.getenv("GOOGLE_API_KEY")
genai.configure(api_key=GOOGLE_API_KEY)
safety_settings = [
{
"category": "HARM_CATEGORY_DANGEROUS",
"threshold": "BLOCK_NONE",
},
{
"category": "HARM_CATEGORY_HARASSMENT",
"threshold": "BLOCK_NONE",
},
{
"category": "HARM_CATEGORY_HATE_SPEECH",
"threshold": "BLOCK_NONE",
},
{
"category": "HARM_CATEGORY_SEXUALLY_EXPLICIT",
"threshold": "BLOCK_NONE",
},
{
"category": "HARM_CATEGORY_DANGEROUS_CONTENT",
"threshold": "BLOCK_NONE",
},
]
st.set_page_config(
page_title="This is Not a Dinosaur",
layout="centered"
)
st.image('static/dino-logo.png',width=100)
st.header("THIS :green[IS] :orange[NOT] A :blue[DINOSAUR]", divider='rainbow')
st.markdown(':green[_Jurassic or Just-a-pic? Let our Dino-Detective decide!_]')
file = st.file_uploader("Upload the photo or image you want to check for any hidden Dinosaurs.", type=["jpg", "jpeg", "png"])
img, result = st.columns(2)
with img:
st.info('Here is your uploaded photograph.', icon="ℹ️")
if file is not None:
image = PIL.Image.open(file)
st.image(file,width=350)
with result:
st.info('Is this a Dinosaur?', icon="ℹ️")
if file is not None:
model = genai.GenerativeModel('gemini-pro-vision',safety_settings=safety_settings)
response = model.generate_content(["Observe the image and reply with a funny note about whether a Dinosaur is present in the image or not.", image], stream=True)
response.resolve()
for candidate in response.candidates:
st.write(part.text for part in candidate.content.parts)
st.link_button('Report Feedback, Issues, or Contribute!', "https://github.com/rajtilakjee/thisisnotadinosaur/issues", use_container_width=True)