File size: 5,090 Bytes
5a18d50
 
 
 
4d4e5c7
5a18d50
fd74ac9
 
 
 
 
eddb11d
 
fd74ac9
eddb11d
5a18d50
 
fd74ac9
5a18d50
fd74ac9
5a18d50
 
 
fd74ac9
 
 
5a18d50
 
fd74ac9
 
 
 
 
 
3866cff
fd74ac9
 
 
 
 
 
 
3866cff
 
fd74ac9
 
 
 
3866cff
 
fd74ac9
 
 
 
 
 
 
eddb11d
c5618a4
eddb11d
 
 
 
 
 
c5618a4
eddb11d
 
 
 
 
 
 
c5618a4
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
eddb11d
 
 
 
fd74ac9
 
 
 
 
 
c5618a4
 
 
 
 
 
 
 
 
 
 
eae3f9f
c5618a4
fd74ac9
 
 
 
 
eddb11d
 
 
 
 
 
 
 
5a18d50
 
 
fd74ac9
eddb11d
 
 
 
 
 
 
fd74ac9
c5618a4
743cb15
eddb11d
743cb15
 
 
 
eae3f9f
743cb15
d34e352
c5618a4
 
 
 
 
5a18d50
 
 
fd74ac9
5a18d50
 
 
 
 
 
3866cff
76f7219
c5618a4
eae3f9f
743cb15
d34e352
c23fc57
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
import streamlit as st
from groq import Groq

# Define the API key here
GROQ_API_KEY = "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"

# Initialize session state for chat history
if "chat_history" not in st.session_state:
    st.session_state.chat_history = [
        {"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."}
    ]
if "previous_sessions" not in st.session_state:
    st.session_state.previous_sessions = []

# Function to fetch response
def fetch_response(user_input):
    client = Groq(api_key=GROQ_API_KEY)
    st.session_state.chat_history.append({"role": "user", "content": user_input})
    chat_completion = client.chat.completions.create(
        messages=st.session_state.chat_history,
        model="mixtral-8x7b-32768",
        stream=False
    )
    response = chat_completion.choices[0].message.content
    st.session_state.chat_history.append({"role": "assistant", "content": response})
    return response

# Streamlit app
st.set_page_config(page_title="Fastest AI Chatbot", page_icon="🤖", layout="wide")

st.markdown(
    """
    <style>
    body {
        background-color: #1f1f2e;
        color: #e1e1e1;
        font-family: 'Courier New', Courier, monospace;
    }
    .css-18e3th9 {
        padding: 2rem;
    }
    .css-1d391kg {
        background: linear-gradient(145deg, #3d3d5c, #2e2e4a);
        box-shadow: 20px 20px 60px #29293f, -20px -20px 60px #3a3a56;
        border-radius: 15px;
        padding: 2rem;
    }
    .stButton>button {
        background: linear-gradient(145deg, #5e5e87, #4a4a6c);
        box-shadow: 8px 8px 16px #29293f, -8px -8px 16px #3a3a56;
        color: #e1e1e1;
        border: none;
        border-radius: 12px;
        padding: 0.5rem 2rem;
        font-size: 1.2rem;
        margin-top: 1rem;
    }
    .chat-container {
        padding-bottom: 100px;
    }
    .chat-input {
        position: fixed;
        bottom: 0;
        left: 50%;
        transform: translateX(-50%);
        width: 60%;
        background: linear-gradient(145deg, #5e5e87, #4a4a6c);
        box-shadow: inset 8px 8px 16px #29293f, inset -8px -8px 16px #3a3a56;
        border: none;
        border-radius: 12px;
        color: #e1e1e1;
        padding: 1rem;
        font-size: 1rem;
        display: flex;
        align-items: center;
    }
    .chat-input input {
        flex: 1;
        background: transparent;
        border: none;
        color: inherit;
        font-size: inherit;
        padding: 0;
        margin: 0;
    }
    .chat-input button {
        background: transparent;
        border: none;
        color: inherit;
        font-size: inherit;
        margin-left: 1rem;
        cursor: pointer;
    }
    .previous-sessions {
        color: #e1e1e1;
    }
    footer {
        color: #e1e1e1;
        font-size: small;
        text-align: right;
        margin-top: 2rem;
    }
    .save-session {
        position: fixed;
        bottom: 10px;
        right: 10px;
        background: linear-gradient(145deg, #5e5e87, #4a4a6c);
        box-shadow: 8px 8px 16px #29293f, -8px -8px 16px #3a3a56;
        border: none;
        border-radius: 12px;
        color: #e1e1e1;
        padding: 0.5rem 2rem;
        font-size: 1rem;
        cursor: pointer;
    }
    </style>
    """,
    unsafe_allow_html=True
)

# Sidebar for previous sessions
st.sidebar.title("Previous Sessions")
st.sidebar.markdown("<div class='previous-sessions'>", unsafe_allow_html=True)
for i, session in enumerate(st.session_state.previous_sessions):
    if st.sidebar.button(f"Session {i + 1}"):
        st.session_state.chat_history = session
st.sidebar.markdown("</div>", unsafe_allow_html=True)

st.title("Fastest AI Chatbot")
st.write("Ask a question and get a response.")

# Display chat history
st.markdown("<div class='chat-container'>", unsafe_allow_html=True)
for chat in st.session_state.chat_history:
    if chat["role"] == "user":
        st.markdown(f"**You:** {chat['content']}")
    elif chat["role"] == "assistant":
        st.markdown(f"**AI:** {chat['content']}")
st.markdown("</div>", unsafe_allow_html=True)

# Custom input field
user_input = st.text_input("Enter your question here:")

# Button to trigger response
if st.button("Get Response"):
    response = fetch_response(user_input)
    st.write("Response:", response)

# Save session button
if st.button("Save Session"):
    st.session_state.previous_sessions.append(st.session_state.chat_history)
    st.session_state.chat_history = [
        {"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."}
    ]

# Footer
st.markdown(
    """
    <footer>
        By DL TITANS
    </footer>
    """,
    unsafe_allow_html=True
)