Spaces:
Runtime error
Runtime error
File size: 7,460 Bytes
256c031 9f9b1da 256c031 9f9b1da 256c031 9f9b1da 256c031 9f9b1da 256c031 9f9b1da 256c031 | 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 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 | 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("""
<style>
:root {
--primary-color: #00f2ff;
--secondary-color: #ff00e6;
--dark-bg: #0a0a1a;
--darker-bg: #050510;
--card-bg: rgba(15, 15, 35, 0.7);
}
body {
background-color: var(--dark-bg);
color: white;
font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
}
.stApp {
background: linear-gradient(135deg, var(--darker-bg) 0%, var(--dark-bg) 100%);
}
.stTextInput>div>div>input, .stTextArea>div>div>textarea {
background-color: rgba(20, 20, 40, 0.8) !important;
color: white !important;
border: 1px solid var(--primary-color) !important;
}
.stButton>button {
background: linear-gradient(90deg, var(--primary-color), var(--secondary-color));
color: black !important;
font-weight: bold;
border: none;
border-radius: 5px;
padding: 0.5rem 1rem;
transition: all 0.3s ease;
}
.stButton>button:hover {
transform: scale(1.05);
box-shadow: 0 0 15px var(--primary-color);
}
.stMarkdown {
color: white;
}
.sidebar .sidebar-content {
background-color: var(--darker-bg);
border-right: 1px solid rgba(0, 242, 255, 0.2);
}
h1, h2, h3 {
background: linear-gradient(90deg, var(--primary-color), var(--secondary-color));
-webkit-background-clip: text;
-webkit-text-fill-color: transparent;
}
.card {
background-color: var(--card-bg);
border-radius: 10px;
padding: 1.5rem;
margin-bottom: 1rem;
border-left: 3px solid var(--primary-color);
box-shadow: 0 4px 20px rgba(0, 0, 0, 0.3);
}
.glow {
animation: glow 2s infinite alternate;
}
@keyframes glow {
from {
box-shadow: 0 0 5px var(--primary-color);
}
to {
box-shadow: 0 0 20px var(--primary-color);
}
}
</style>
""", 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"<div class='card glow'>{result}</div>", 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("""
<div class='card'>
<h4>Welcome to NeuraVision AI</h4>
<p>Upload an image and provide a prompt to get started with quantum-powered analysis.</p>
<p>Try prompts like:</p>
<ul>
<li>"Describe this image in detail"</li>
<li>"What emotions does this image convey?"</li>
<li>"Analyze the composition and artistic elements"</li>
</ul>
</div>
""", 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("""
<div class='card'>
<p>System Status: <span style='color: var(--primary-color)'>Online</span></p>
<p>Model: LLaMA 4 Scout 17B</p>
<p>Processor: Quantum Core</p>
</div>
""", 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() |