File size: 1,872 Bytes
f0a1f4f
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import PIL.Image
import streamlit as st
import google.generativeai as genai
import os
from PIL import Image

def DETECTIMAGE():
    st.title("Create photoshoot visual")

    # Set the directory where the uploaded images will be saved
    UPLOAD_DIR = 'Assets/uploaded_images'

    # Create the directory if it doesn't exist
    if not os.path.exists(UPLOAD_DIR):
        os.makedirs(UPLOAD_DIR)

    # Streamlit app title
    st.header("Upload Image")

    # File uploader allows user to upload an image
    uploaded_file = st.file_uploader("Choose an image...", type=["jpg", "jpeg", "png"])

    if uploaded_file is not None:
        with st.spinner('Processing the image...'):
            # Open the uploaded image
            image = Image.open(uploaded_file)

            # Save the uploaded image to the specified directory
            image_path = os.path.join(UPLOAD_DIR, uploaded_file.name)
            image.save(image_path)

            img = PIL.Image.open(image_path)
            st.image(img, caption="Uploaded Image")

            # Or use `os.getenv('GOOGLE_API_KEY')` to fetch an environment variable.
            GOOGLE_API_KEY = st.secrets["GOOGLE_API_KEY"]

            genai.configure(api_key=GOOGLE_API_KEY)

            model = genai.GenerativeModel('gemini-1.5-flash')

            # Generate content
            response = model.generate_content(["Is the image anything from this list? (Shoe,Sneaker, Bottle, Cup, Sandal, Perfume, Toy, Sunglasses, Car, Water Bottle,Chair, Office Chair, Can, Cap, Hat, Couch, Wristwatch, Glass, Bag, Handbag, Baggage, Suitcase, Headphones, Jar, Vase) If yes then give only the object name, if no simply say 'Not Recognized' and dont give any fullstop at the end.", img], stream=True)
            response.resolve()

            st.subheader(f"Output: {response.text}")

if __name__ == "__main__":
    DETECTIMAGE()