CoolFace
Apppublic

MRGGaze/Mythos_Refactor_Gaze

sourceHugging Faceapache-2.0updated 5mo agoView on Hugging Face
0likes
app.py84 linesDownload Raw Back to root
1import streamlit as st2from groq import Groq3import os4 5# 1. Page Config6st.set_page_config(page_title="MRG AI", layout="centered")7 8# 2. Custom CSS for Left/Right Chat Bubbles9st.markdown("""10    <style>11    /* Hide Streamlit junk */12    #MainMenu, footer, header {visibility: hidden;}13    14    /* Global Styles */15    .stApp { background-color: #ffffff; }16 17    /* Fix chat alignment: User on right, AI on left */18    [data-testid="stChatMessage"] {19        background-color: transparent !important;20    }21    22    /* Remove avatars/images */23    [data-testid="stChatMessageAvatarUser"], [data-testid="stChatMessageAvatarAssistant"] {24        display: none !important;25    }26 27    /* Style for User Message (Right) */28    [data-testid="chatAvatarIcon-user"] { display: none; }29    .st-emotion-cache-jan706 { flex-direction: row-reverse; text-align: right; }30 31    /* Minimalist input bar */32    .stChatInputContainer { padding-bottom: 20px; }33    </style>34    """, unsafe_allow_html=True)35 36# 3. API Setup37api_key = os.environ.get("GROQ_API_KEY")38if not api_key:39    st.error("Please add GROQ_API_KEY to Space Secrets.")40    st.stop()41 42client = Groq(api_key=api_key)43 44# 4. Initialize History45if "messages" not in st.session_state:46    st.session_state.messages = []47 48# 5. Header49st.markdown("<h2 style='text-align: center; font-family: sans-serif; font-weight: 300;'>MRG AI</h2>", unsafe_allow_html=True)50 51# 6. Display History52for message in st.session_state.messages:53    with st.chat_message(message["role"]):54        st.markdown(message["content"])55 56# 7. Chat Logic57if prompt := st.chat_input("Ask me anything..."):58    # Show User Message59    st.session_state.messages.append({"role": "user", "content": prompt})60    with st.chat_message("user"):61        st.markdown(prompt)62 63    # Generate AI Response64    with st.chat_message("assistant"):65        try:66            # Fixing the 'list' object error here67            chat_completion = client.chat.completions.create(68                model="llama-3.3-70b-versatile",69                messages=[70                    {"role": "system", "content": "You are MRG AI. Provide precise, expert-level refactoring advice."},71                    *[{"role": m["role"], "content": m["content"]} for m in st.session_state.messages]72                ],73                temperature=0.174            )75            76            # THE FIX: Proper way to access content77            full_response = chat_completion.choices[0].message.content78            79            st.markdown(full_response)80            st.session_state.messages.append({"role": "assistant", "content": full_response})81            82        except Exception as e:83            st.error(f"Engine Error: {str(e)}")84