import streamlit as st from groq import Groq import base64 from PIL import Image import io import time # Set page config for futuristic theme st.set_page_config( page_title="NeuraVision AI", page_icon="🔮", layout="wide", initial_sidebar_state="expanded" ) # Custom CSS for futuristic aesthetic def set_custom_css(): st.markdown(""" """, unsafe_allow_html=True) set_custom_css() # Encode image to base64 def encode_image_to_base64(image): buffered = io.BytesIO() image.save(buffered, format="JPEG") return base64.b64encode(buffered.getvalue()).decode("utf-8") # Prediction function def analyze_image(api_key, image, prompt): if not api_key: return "❌ Please provide your Groq API key." try: client = Groq(api_key=api_key) base64_image = encode_image_to_base64(image) with st.spinner('🌀 Processing image with quantum neural networks...'): time.sleep(1) # For dramatic effect response = client.chat.completions.create( model="meta-llama/llama-4-scout-17b-16e-instruct", messages=[ { "role": "user", "content": [ {"type": "text", "text": prompt}, {"type": "image_url", "image_url": {"url": f"data:image/jpeg;base64,{base64_image}"}} ] } ], max_tokens=1024, ) return response.choices[0].message.content except Exception as e: return f"⚠️ Error: {str(e)}" # App layout def main(): st.title("🔮 NeuraVision AI") st.markdown("### Quantum-Powered Image Analysis with Groq & LLaMA 4 Scout") st.markdown("---") col1, col2 = st.columns([1, 2]) with col1: with st.container(): st.markdown("### ⚙️ Configuration Panel") api_key = st.text_input("🔑 Groq API Key", type="password", help="Enter your Groq API key") uploaded_file = st.file_uploader("📸 Upload Image", type=["png", "jpg", "jpeg"], help="Upload an image for analysis") prompt = st.text_area("💬 Analysis Prompt", value="Describe this image in detail, including all important elements and their relationships.", height=150) if st.button("🚀 Analyze Image", use_container_width=True): if uploaded_file is not None: image = Image.open(uploaded_file) with col2: with st.container(): st.markdown("### 🔍 Analysis Results") st.image(image, caption="Uploaded Image", width=300) result = analyze_image(api_key, image, prompt) st.markdown("### 📝 Insights") st.markdown(f"
{result}
", unsafe_allow_html=True) else: st.warning("Please upload an image first.") with col2: if 'result' not in st.session_state: st.markdown("### 🔍 Analysis Results") st.markdown("""

Welcome to NeuraVision AI

Upload an image and provide a prompt to get started with quantum-powered analysis.

Try prompts like:

""", unsafe_allow_html=True) st.image("https://via.placeholder.com/600x400/0a0a1a/00f2ff?text=Upload+an+Image", caption="Your analysis will appear here", width=400) # Sidebar with st.sidebar: st.markdown("## 🌌 Quantum Console") st.markdown("""

System Status: Online

Model: LLaMA 4 Scout 17B

Processor: Quantum Core

""", unsafe_allow_html=True) st.markdown("### ⚡ Quick Prompts") if st.button("Describe technically"): st.session_state.prompt = "Provide a detailed technical description of this image, including objects, colors, composition, and any notable features." if st.button("Analyze emotions"): st.session_state.prompt = "What emotions does this image convey? Describe the mood, atmosphere, and any emotional elements present." if st.button("Artistic critique"): st.session_state.prompt = "Provide an artistic critique of this image, discussing composition, color theory, lighting, and artistic merit." if __name__ == "__main__": main()