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"
Upload an image and provide a prompt to get started with quantum-powered analysis.
Try prompts like:
System Status: Online
Model: LLaMA 4 Scout 17B
Processor: Quantum Core