Spaces:
Sleeping
Sleeping
import streamlit as st | |
import os | |
from dotenv import load_dotenv | |
import google.generativeai as genai | |
# Load environment variables | |
load_dotenv() | |
GOOGLE_API_KEY = os.getenv("GOOGLE_API_KEY") | |
# Validate API Key | |
if not GOOGLE_API_KEY: | |
st.error("Google Gemini API key not found. Please set GOOGLE_API_KEY in your .env file.") | |
st.stop() | |
# Configure Gemini | |
genai.configure(api_key=GOOGLE_API_KEY) | |
# Streamlit page setup | |
st.set_page_config(page_title="NeuraNexus: AI-Powered ML Assistant", page_icon="π§ ", layout="wide") | |
# ============================== | |
# Custom CSS (include your full CSS here) | |
# ============================== | |
st.markdown(""" | |
<style> | |
body { | |
background-color: #0F1C2E; | |
color: white; | |
font-family: 'Roboto', sans-serif; | |
} | |
h1 { | |
font-family: 'Orbitron', sans-serif; | |
color: #FF6B6B; | |
text-align: center; | |
font-size: 2.5em; | |
text-shadow: 0 0 10px rgba(255, 107, 107, 0.7); | |
} | |
.result-container { | |
background: rgba(255, 255, 255, 0.05); | |
border: 1px solid rgba(74, 144, 226, 0.2); | |
border-radius: 15px; | |
padding: 20px; | |
margin-top: 30px; | |
color: white; | |
box-shadow: 0 8px 32px 0 rgba(31, 38, 135, 0.2); | |
backdrop-filter: blur(10px); | |
} | |
.by-theaimart { | |
text-align: center; | |
font-size: 20px; | |
color: #50E3C2; | |
margin-top: 20px; | |
font-weight: bold; | |
} | |
</style> | |
""", unsafe_allow_html=True) | |
# ============================== | |
# App UI | |
# ============================== | |
st.markdown('<h1 class="glow">NeuraNexus: AI-Powered ML Assistant</h1>', unsafe_allow_html=True) | |
st.markdown('<h3 style="text-align:center;">Describe your ML challenge, and let NeuraNexus craft an innovative solution.</h3>', unsafe_allow_html=True) | |
# Input from user | |
user_prompt = st.text_area("Your ML Challenge", height=150, placeholder="Enter your machine learning challenge here...") | |
if 'response' not in st.session_state: | |
st.session_state.response = "" | |
# Generate button | |
if st.button("SYNTHESIZE"): | |
if not user_prompt.strip(): | |
st.warning("Please describe your ML challenge first.") | |
else: | |
with st.spinner("NeuraNexus is thinking..."): | |
try: | |
model = genai.GenerativeModel("gemini-pro") | |
chat = model.start_chat() | |
system_prompt = "You are NeuraNexus, an AI specialized in designing innovative and actionable ML strategies. Provide expert-level solutions to the given ML challenge." | |
full_prompt = f"{system_prompt}\n\nUser Problem:\n{user_prompt}" | |
response = chat.send_message(full_prompt) | |
st.session_state.response = response.text | |
st.success("Synthesis complete!") | |
except Exception as e: | |
st.session_state.response = f"β Error: {e}" | |
st.error("Gemini synthesis failed.") | |
# ============================== | |
# Show result | |
# ============================== | |
if st.session_state.response: | |
st.markdown("### NeuraNexus Synthesis Result") | |
st.markdown(f""" | |
<div class="result-container"> | |
{st.session_state.response} | |
</div> | |
""", unsafe_allow_html=True) | |
# Footer | |
st.markdown('<p class="by-theaimart">By Theaimart</p>', unsafe_allow_html=True) | |
# Run wrapper | |
def main(): | |
pass | |
if __name__ == "__main__": | |
main() | |