File size: 4,131 Bytes
c80a64e
 
 
 
 
 
 
 
 
d0b3977
c80a64e
 
 
 
 
d0b3977
 
 
37bd679
d0b3977
c80a64e
 
d0b3977
c80a64e
 
 
 
 
 
 
 
d0b3977
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
37bd679
 
 
d0b3977
 
37bd679
 
 
 
 
 
 
d0b3977
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
c80a64e
d0b3977
 
 
 
 
37bd679
d0b3977
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
c80a64e
d0b3977
 
37bd679
c80a64e
d0b3977
 
 
 
 
 
 
c80a64e
d0b3977
 
 
 
c80a64e
d0b3977
 
c80a64e
d0b3977
 
 
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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
import streamlit as st
import google.generativeai as genai
import os

# Configure the API key
api_key = 'AIzaSyC13hxiLDZQagfXybLKCklbTlBDsO4vHwQ'
genai.configure(api_key=api_key)

# Function to upload and process the image
def process_image(image_path, user_question=None):
    try:
        # Upload the image to Google Generative AI
        sample_file = genai.upload_file(path=image_path, display_name="Sample drawing")

        # Use the Generative AI model to analyze the image
        model = genai.GenerativeModel(model_name="models/gemini-2.0-flash-exp")

        # Prepare the prompt
        prompt = user_question if user_question else "Explain the scene in the image in detail."
        response = model.generate_content([prompt, sample_file])

        # Display the response
        st.write("**VisioX Analysis:**")
        st.write(response.text)

        # Delete the uploaded file
        genai.delete_file(sample_file.name)

    except Exception as e:
        st.error(f"An error occurred: {e}")

# Custom CSS for cyberpunk styling
def set_cyberpunk_style():
    st.markdown(
        """
        <style>
        @import url('https://fonts.googleapis.com/css2?family=Orbitron:wght@900&family=Roboto+Mono:wght@300&display=swap');

        html, body, [class*="css"] {
            font-family: 'Roboto Mono', monospace;
            color: #00ff00;
            background-color: #0a0a0a;
        }

        h1, h2, h3, h4, h5, h6 {
            font-family: 'Orbitron', sans-serif;
            color: #ff00ff !important;
        }

        .stButton button {
            background-color: #000000 !important;
            color: #00ff00 !important;
            border: 2px solid #00ff00 !important;
            font-family: 'Orbitron', sans-serif;
            font-weight: bold;
            transition: all 0.3s ease;
        }

        .stButton button:hover {
            background-color: #00ff00 !important;
            color: #000000 !important;
            border: 2px solid #000000 !important;
        }

        .stTextInput input {
            background-color: #0a0a0a;
            color: #00ff00;
            border: 2px solid #ff00ff;
        }

        .stCameraInput {
            border: 2px solid #ff00ff;
            border-radius: 10px;
        }

        .stImage img {
            border: 2px solid #00ff00;
            border-radius: 10px;
        }

        .stSpinner div {
            color: #ff00ff !important;
        }

        .stMarkdown {
            color: #00ff00 !important;
        }
        </style>
        """,
        unsafe_allow_html=True,
    )

# Streamlit app
def main():
    # Set cyberpunk style
    set_cyberpunk_style()

    # App title and description
    st.title("VisioX : SXR")
    st.markdown(
        """
        <div style="color: #00ff00;">
        Welcome to <span style="color: #ff00ff;">VisioX</span>, the ultimate AI-powered vision analyzer.
        Capture an image, and let VisioX explain the scene or answer your questions.
        </div>
        """,
        unsafe_allow_html=True,
    )

    # Access the camera and capture an image
    st.markdown("### Capture an Image")
    picture = st.camera_input("Take a picture")

    if picture:
        # Save the captured image to a temporary file
        image_path = "captured_image.png"
        with open(image_path, "wb") as f:
            f.write(picture.getbuffer())

        # Display the captured image
        st.markdown("### Captured Image")
        st.image(image_path, caption="Your Moment")

        # Add a text input for user questions
        st.markdown("### Ask a Question")
        user_question = st.text_input(
            "Ask a question about the image (optional):",
            placeholder="e.g., What is in the background?",
            key="question_input",
        )

        # Process the image
        if st.button("Analyze with VisioX"):
            with st.spinner("VisioX is analyzing your image..."):
                process_image(image_path, user_question)

        # Clean up the temporary file
        os.remove(image_path)

# Run the app
if __name__ == "__main__":
    main()