Lalitr commited on
Commit
2d38233
1 Parent(s): 32d79e8

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +46 -46
app.py CHANGED
@@ -1,46 +1,46 @@
1
- import google.generativeai as genai
2
- import streamlit as st
3
- import numpy as np
4
- from PIL import Image
5
- #from dotenv import load_dotenv
6
- #load_dotenv()
7
- import json
8
-
9
- import os
10
- GOOGLE_API_KEY=os.getenv('GOOGLE_API_KEY')
11
- genai.configure(api_key=GOOGLE_API_KEY)
12
-
13
- st.set_page_config(page_title='Description Generator',
14
- page_icon=':milky_way:',
15
- layout='centered',
16
- initial_sidebar_state='collapsed'
17
- )
18
-
19
- st.header('Description Generator')
20
-
21
- uploaded_file = st.file_uploader("Choose a file", type=["jpg", "jpeg", "png"])
22
- if uploaded_file is not None:
23
- # To read file as bytes:
24
- #bytes_data = uploaded_file.getvalue()
25
- file_bytes = np.asarray(bytearray(uploaded_file.read()), dtype=np.uint8)
26
- st.image(uploaded_file)
27
-
28
- #from IPython.display import Image
29
- img = Image.open(uploaded_file)
30
-
31
- prompt = """This image contains a sketch.
32
- try to identify and Describe the sketch as thoroughly as possible based on what you
33
- see in the image, making sure to note all of the features. Return output in json format:
34
- {description: description, features: [feature1, feature2, feature3, etc]}"""
35
-
36
- submit=st.button('Generate')
37
-
38
- if submit:
39
- model = genai.GenerativeModel('gemini-1.5-flash')
40
- response = model.generate_content([prompt, img])
41
- response=json.loads(response.text)
42
- st.write((response['description']))
43
- number=1
44
- for feature in response['features']:
45
- st.write("Feature "+str(number)+" : "+str(feature))
46
- number+=1
 
1
+ import google.generativeai as genai
2
+ import streamlit as st
3
+ import numpy as np
4
+ from PIL import Image
5
+ #from dotenv import load_dotenv
6
+ #load_dotenv()
7
+ import json
8
+
9
+ import os
10
+ GOOGLE_API_KEY=os.getenv('GOOGLE_API_KEY')
11
+ genai.configure(api_key=GOOGLE_API_KEY)
12
+
13
+ st.set_page_config(page_title='Description Generator',
14
+ page_icon=':milky_way:',
15
+ layout='centered',
16
+ initial_sidebar_state='collapsed'
17
+ )
18
+
19
+ st.header('Image Description Generator(Share Image get description)')
20
+
21
+ uploaded_file = st.file_uploader("Choose a file", type=["jpg", "jpeg", "png"])
22
+ if uploaded_file is not None:
23
+ # To read file as bytes:
24
+ #bytes_data = uploaded_file.getvalue()
25
+ file_bytes = np.asarray(bytearray(uploaded_file.read()), dtype=np.uint8)
26
+ st.image(uploaded_file)
27
+
28
+ #from IPython.display import Image
29
+ img = Image.open(uploaded_file)
30
+
31
+ prompt = """This image contains a sketch.
32
+ try to identify and Describe the sketch as thoroughly as possible based on what you
33
+ see in the image, making sure to note all of the features. Return output in json format:
34
+ {description: description, features: [feature1, feature2, feature3, etc]}"""
35
+
36
+ submit=st.button('Generate')
37
+
38
+ if submit:
39
+ model = genai.GenerativeModel('gemini-1.5-flash')
40
+ response = model.generate_content([prompt, img])
41
+ response=json.loads(response.text)
42
+ st.write((response['description']))
43
+ number=1
44
+ for feature in response['features']:
45
+ st.write("Feature "+str(number)+" : "+str(feature))
46
+ number+=1