Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -9,8 +9,10 @@ if "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 |
]
|
|
|
|
|
12 |
|
13 |
-
#
|
14 |
def fetch_response(user_input):
|
15 |
client = Groq(api_key=GROQ_API_KEY)
|
16 |
st.session_state.chat_history.append({"role": "user", "content": user_input})
|
@@ -62,6 +64,26 @@ st.markdown(
|
|
62 |
padding: 1rem;
|
63 |
font-size: 1rem;
|
64 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
65 |
footer {
|
66 |
color: #e1e1e1;
|
67 |
font-size: small;
|
@@ -73,30 +95,55 @@ st.markdown(
|
|
73 |
unsafe_allow_html=True
|
74 |
)
|
75 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
76 |
st.title("Fastest AI Chatbot")
|
77 |
st.write("Ask a question and get a response.")
|
78 |
|
79 |
-
# Function to display chat history
|
80 |
-
def display_chat_history():
|
81 |
-
for chat in st.session_state.chat_history:
|
82 |
-
if chat["role"] == "user":
|
83 |
-
st.markdown(f"**You:** {chat['content']}")
|
84 |
-
elif chat["role"] == "assistant":
|
85 |
-
st.markdown(f"**AI:** {chat['content']}")
|
86 |
-
|
87 |
# Display chat history
|
88 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
89 |
|
90 |
# Text input for user's question
|
91 |
-
user_input = st.text_input("Enter your question here:", key="input")
|
92 |
|
93 |
# Button to trigger response
|
94 |
-
if st.button("Get Response"):
|
95 |
if user_input:
|
96 |
# Fetch and display response
|
97 |
-
|
98 |
st.experimental_rerun()
|
99 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
100 |
# Footer
|
101 |
st.markdown(
|
102 |
"""
|
|
|
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 |
]
|
12 |
+
if "previous_sessions" not in st.session_state:
|
13 |
+
st.session_state.previous_sessions = []
|
14 |
|
15 |
+
# Function to fetch response
|
16 |
def fetch_response(user_input):
|
17 |
client = Groq(api_key=GROQ_API_KEY)
|
18 |
st.session_state.chat_history.append({"role": "user", "content": user_input})
|
|
|
64 |
padding: 1rem;
|
65 |
font-size: 1rem;
|
66 |
}
|
67 |
+
.chat-container {
|
68 |
+
padding-bottom: 50px;
|
69 |
+
}
|
70 |
+
.chat-input {
|
71 |
+
position: fixed;
|
72 |
+
bottom: 0;
|
73 |
+
left: 50%;
|
74 |
+
transform: translateX(-50%);
|
75 |
+
width: 50%;
|
76 |
+
background: linear-gradient(145deg, #5e5e87, #4a4a6c);
|
77 |
+
box-shadow: inset 8px 8px 16px #29293f, inset -8px -8px 16px #3a3a56;
|
78 |
+
border: none;
|
79 |
+
border-radius: 12px;
|
80 |
+
color: #e1e1e1;
|
81 |
+
padding: 1rem;
|
82 |
+
font-size: 1rem;
|
83 |
+
}
|
84 |
+
.previous-sessions {
|
85 |
+
color: #e1e1e1;
|
86 |
+
}
|
87 |
footer {
|
88 |
color: #e1e1e1;
|
89 |
font-size: small;
|
|
|
95 |
unsafe_allow_html=True
|
96 |
)
|
97 |
|
98 |
+
# Sidebar for previous sessions
|
99 |
+
st.sidebar.title("Previous Sessions")
|
100 |
+
st.sidebar.markdown("<div class='previous-sessions'>", unsafe_allow_html=True)
|
101 |
+
for i, session in enumerate(st.session_state.previous_sessions):
|
102 |
+
if st.sidebar.button(f"Session {i + 1}"):
|
103 |
+
st.session_state.chat_history = session
|
104 |
+
st.sidebar.markdown("</div>", unsafe_allow_html=True)
|
105 |
+
|
106 |
st.title("Fastest AI Chatbot")
|
107 |
st.write("Ask a question and get a response.")
|
108 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
109 |
# Display chat history
|
110 |
+
st.markdown("<div class='chat-container'>", unsafe_allow_html=True)
|
111 |
+
for chat in st.session_state.chat_history:
|
112 |
+
if chat["role"] == "user":
|
113 |
+
st.markdown(f"**You:** {chat['content']}")
|
114 |
+
elif chat["role"] == "assistant":
|
115 |
+
st.markdown(f"**AI:** {chat['content']}")
|
116 |
+
st.markdown("</div>", unsafe_allow_html=True)
|
117 |
|
118 |
# Text input for user's question
|
119 |
+
user_input = st.text_input("Enter your question here:", key="input", label_visibility='collapsed', placeholder='Type your message here...')
|
120 |
|
121 |
# Button to trigger response
|
122 |
+
if st.button("Get Response", key="get_response"):
|
123 |
if user_input:
|
124 |
# Fetch and display response
|
125 |
+
fetch_response(user_input)
|
126 |
st.experimental_rerun()
|
127 |
|
128 |
+
# Save session state when user leaves
|
129 |
+
if st.button("Save Session"):
|
130 |
+
st.session_state.previous_sessions.append(st.session_state.chat_history)
|
131 |
+
st.session_state.chat_history = [
|
132 |
+
{"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."}
|
133 |
+
]
|
134 |
+
st.experimental_rerun()
|
135 |
+
|
136 |
+
# Display the permanent input field at the bottom center
|
137 |
+
st.markdown(
|
138 |
+
"""
|
139 |
+
<div class="chat-input">
|
140 |
+
<input type="text" id="chat-input-field" placeholder="Type your message here..." onkeydown="if(event.key === 'Enter'){document.getElementById('chat-submit-button').click();}">
|
141 |
+
<button id="chat-submit-button" onclick="document.querySelector('button[kind=primary][key=get_response]').click();">Send</button>
|
142 |
+
</div>
|
143 |
+
""",
|
144 |
+
unsafe_allow_html=True
|
145 |
+
)
|
146 |
+
|
147 |
# Footer
|
148 |
st.markdown(
|
149 |
"""
|