ManasviD commited on
Commit
cfafec9
·
verified ·
1 Parent(s): 2b8bc58

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +63 -0
app.py ADDED
@@ -0,0 +1,63 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ import os
3
+ import google.generativeai as genai
4
+ from PIL import Image
5
+
6
+
7
+
8
+ ## Function to load Google Gemini Pro Vision API And get response
9
+
10
+ def get_gemini_repsonse(input,image,prompt):
11
+ model=genai.GenerativeModel('gemini-1.5-flash')
12
+ response=model.generate_content([input,image[0],prompt])
13
+ return response.text
14
+
15
+ def input_image_setup(uploaded_file):
16
+ # Check if a file has been uploaded
17
+ if uploaded_file is not None:
18
+ # Read the file into bytes
19
+ bytes_data = uploaded_file.getvalue()
20
+
21
+ image_parts = [
22
+ {
23
+ "mime_type": uploaded_file.type, # Get the mime type of the uploaded file
24
+ "data": bytes_data
25
+ }
26
+ ]
27
+ return image_parts
28
+ else:
29
+ raise FileNotFoundError("No file uploaded")
30
+
31
+ ##initialize our streamlit app
32
+
33
+ st.set_page_config(page_title="Biodiversity Detection App")
34
+
35
+ st.header("Biodiversity")
36
+ input=st.text_input("Input Prompt: ",key="input")
37
+ uploaded_file = st.file_uploader("Choose an image...", type=["jpg", "jpeg", "png"])
38
+ image=""
39
+ if uploaded_file is not None:
40
+ image = Image.open(uploaded_file)
41
+ st.image(image, caption="Uploaded Image.", use_column_width=True)
42
+
43
+
44
+ submit=st.button("Find the Species")
45
+
46
+ input_prompt="""
47
+ you are an expert taxonomist where you need to see the image and return detailed info about the species including its Name,common name,Kingdom,phylum and class,family ,genus,native country .
48
+ Also generate a short informatie ,engaging 150 words story like national geographic story about that species,it's life and history with other images of same species (in both text and audio format).
49
+ the image you can answer is of only living organisms like animals,plants etc.
50
+ Do not return results for non-living objects.
51
+ If image does not contain living organism or something which you do not know respond with invalid input.
52
+
53
+
54
+ """
55
+
56
+ ## If submit button is clicked
57
+
58
+ if submit:
59
+ image_data=input_image_setup(uploaded_file)
60
+ response=get_gemini_repsonse(input_prompt,image_data,input)
61
+
62
+ st.write(response)
63
+