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( """ """, unsafe_allow_html=True, ) # Streamlit app def main(): # Set cyberpunk style set_cyberpunk_style() # App title and description st.title("VisioX : SXR") st.markdown( """
Welcome to VisioX, the ultimate AI-powered vision analyzer. Capture an image, and let VisioX explain the scene or answer your questions.
""", 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()