CoolFace
Apppublic

DL-TITANS/Fastest-bot-test

sourceHugging Facemitupdated 2y agoView on Hugging Face
0likes
app.py173 linesDownload Raw Back to root
1import streamlit as st2from groq import Groq3 4# Define the API key here5GROQ_API_KEY = "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"6 7# Initialize session state for chat history8if "chat_history" not in st.session_state:9    st.session_state.chat_history = [10        {"role": "system", "content": "you are a helpful assistant. Take the input from the users and try to provide as detailed response as possible. Provide proper examples to help the user. Try to mention references or provide citations to make it more detail-oriented."}11    ]12if "previous_sessions" not in st.session_state:13    st.session_state.previous_sessions = []14 15# Function to fetch response16def fetch_response(user_input):17    client = Groq(api_key=GROQ_API_KEY)18    st.session_state.chat_history.append({"role": "user", "content": user_input})19    chat_completion = client.chat.completions.create(20        messages=st.session_state.chat_history,21        model="mixtral-8x7b-32768",22        stream=False23    )24    response = chat_completion.choices[0].message.content25    st.session_state.chat_history.append({"role": "assistant", "content": response})26    return response27 28# Streamlit app29st.set_page_config(page_title="Fastest AI Chatbot", page_icon="🤖", layout="wide")30 31st.markdown(32    """33    <style>34    body {35        background-color: #1f1f2e;36        color: #e1e1e1;37        font-family: 'Courier New', Courier, monospace;38    }39    .css-18e3th9 {40        padding: 2rem;41    }42    .css-1d391kg {43        background: linear-gradient(145deg, #3d3d5c, #2e2e4a);44        box-shadow: 20px 20px 60px #29293f, -20px -20px 60px #3a3a56;45        border-radius: 15px;46        padding: 2rem;47    }48    .stButton>button {49        background: linear-gradient(145deg, #5e5e87, #4a4a6c);50        box-shadow: 8px 8px 16px #29293f, -8px -8px 16px #3a3a56;51        color: #e1e1e1;52        border: none;53        border-radius: 12px;54        padding: 0.5rem 2rem;55        font-size: 1.2rem;56        margin-top: 1rem;57    }58    .chat-container {59        padding-bottom: 100px;60    }61    .chat-input {62        position: fixed;63        bottom: 0;64        left: 50%;65        transform: translateX(-50%);66        width: 60%;67        background: linear-gradient(145deg, #5e5e87, #4a4a6c);68        box-shadow: inset 8px 8px 16px #29293f, inset -8px -8px 16px #3a3a56;69        border: none;70        border-radius: 12px;71        color: #e1e1e1;72        padding: 1rem;73        font-size: 1rem;74        display: flex;75        align-items: center;76    }77    .chat-input input {78        flex: 1;79        background: transparent;80        border: none;81        color: inherit;82        font-size: inherit;83        padding: 0;84        margin: 0;85    }86    .chat-input button {87        background: transparent;88        border: none;89        color: inherit;90        font-size: inherit;91        margin-left: 1rem;92        cursor: pointer;93    }94    .previous-sessions {95        color: #e1e1e1;96    }97    footer {98        color: #e1e1e1;99        font-size: small;100        text-align: right;101        margin-top: 2rem;102    }103    .save-session {104        position: fixed;105        bottom: 10px;106        right: 10px;107        background: linear-gradient(145deg, #5e5e87, #4a4a6c);108        box-shadow: 8px 8px 16px #29293f, -8px -8px 16px #3a3a56;109        border: none;110        border-radius: 12px;111        color: #e1e1e1;112        padding: 0.5rem 2rem;113        font-size: 1rem;114        cursor: pointer;115    }116    </style>117    """,118    unsafe_allow_html=True119)120 121# Sidebar for previous sessions122st.sidebar.title("Previous Sessions")123st.sidebar.markdown("<div class='previous-sessions'>", unsafe_allow_html=True)124for i, session in enumerate(st.session_state.previous_sessions):125    if st.sidebar.button(f"Session {i + 1}"):126        st.session_state.chat_history = session127st.sidebar.markdown("</div>", unsafe_allow_html=True)128 129st.title("Fastest AI Chatbot")130st.write("Ask a question and get a response.")131 132# Display chat history133st.markdown("<div class='chat-container'>", unsafe_allow_html=True)134for chat in st.session_state.chat_history:135    if chat["role"] == "user":136        st.markdown(f"**You:** {chat['content']}")137    elif chat["role"] == "assistant":138        st.markdown(f"**AI:** {chat['content']}")139st.markdown("</div>", unsafe_allow_html=True)140 141# Custom input field142user_input = st.text_input("Enter your question here:")143 144# Button to trigger response145if st.button("Get Response"):146    response = fetch_response(user_input)147    st.write("Response:", response)148 149# Save session button150if st.button("Save Session"):151    st.session_state.previous_sessions.append(st.session_state.chat_history)152    st.session_state.chat_history = [153        {"role": "system", "content": "you are a helpful assistant. Take the input from the users and try to provide as detailed response as possible. Provide proper examples to help the user. Try to mention references or provide citations to make it more detail-oriented."}154    ]155 156# Footer157st.markdown(158    """159    <footer>160        By DL TITANS161    </footer>162    """,163    unsafe_allow_html=True164)165 166 167 168 169 170 171 172 173