Update app.py
Browse files
app.py
CHANGED
|
@@ -1,6 +1,7 @@
|
|
| 1 |
import os
|
| 2 |
import streamlit as st
|
| 3 |
import pandas as pd
|
|
|
|
| 4 |
|
| 5 |
# Set page layout to wide mode
|
| 6 |
st.set_page_config(layout="wide")
|
|
@@ -62,5 +63,58 @@ if st.session_state.logged_in:
|
|
| 62 |
|
| 63 |
# Render the DataFrame with the URL as a hyperlink
|
| 64 |
st.markdown(df.to_markdown(index=False), unsafe_allow_html=True)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 65 |
else:
|
| 66 |
st.info("π Please log in to view the tasks.")
|
|
|
|
| 1 |
import os
|
| 2 |
import streamlit as st
|
| 3 |
import pandas as pd
|
| 4 |
+
from utils.helper import *
|
| 5 |
|
| 6 |
# Set page layout to wide mode
|
| 7 |
st.set_page_config(layout="wide")
|
|
|
|
| 63 |
|
| 64 |
# Render the DataFrame with the URL as a hyperlink
|
| 65 |
st.markdown(df.to_markdown(index=False), unsafe_allow_html=True)
|
| 66 |
+
|
| 67 |
+
# Chatbot
|
| 68 |
+
with st.sidebar:
|
| 69 |
+
# Add a button to clear the session state
|
| 70 |
+
if st.button("Clear Session"):
|
| 71 |
+
st.session_state.messages = []
|
| 72 |
+
st.experimental_rerun()
|
| 73 |
+
|
| 74 |
+
# Initialize chat history
|
| 75 |
+
if "messages" not in st.session_state:
|
| 76 |
+
st.session_state.messages = []
|
| 77 |
+
|
| 78 |
+
# Ensure messages are a list of dictionaries
|
| 79 |
+
if not isinstance(st.session_state.messages, list):
|
| 80 |
+
st.session_state.messages = []
|
| 81 |
+
if not all(isinstance(msg, dict) for msg in st.session_state.messages):
|
| 82 |
+
st.session_state.messages = []
|
| 83 |
+
|
| 84 |
+
# Display chat messages from history on app rerun
|
| 85 |
+
for message in st.session_state.messages:
|
| 86 |
+
with st.chat_message(message["role"]):
|
| 87 |
+
st.markdown(message["content"])
|
| 88 |
+
|
| 89 |
+
# React to user input
|
| 90 |
+
if prompt := st.chat_input("π What GPU shall I use?"):
|
| 91 |
+
|
| 92 |
+
# Display user message in chat message container
|
| 93 |
+
st.chat_message("user").markdown(prompt)
|
| 94 |
+
|
| 95 |
+
# Add user message to chat history
|
| 96 |
+
st.session_state.messages.append({"role": "system", "content": f"""
|
| 97 |
+
You are a helpful assistant assiting users on GPU selections.
|
| 98 |
+
Here's the data:
|
| 99 |
+
{df.to_markdown(index=False)}
|
| 100 |
+
|
| 101 |
+
User may ask what is the best GPU selection.
|
| 102 |
+
You will need to ask user: 1) type of task, 2) size of data, 3) size of models.
|
| 103 |
+
You will then make a suggestion of what type of GPU or instance is the best for the user.
|
| 104 |
+
"""})
|
| 105 |
+
st.session_state.messages.append({"role": "user", "content": prompt})
|
| 106 |
+
|
| 107 |
+
# API Call
|
| 108 |
+
bot = ChatBot()
|
| 109 |
+
bot.history = st.session_state.messages.copy() # Update history from messages
|
| 110 |
+
response = bot.generate_response(prompt)
|
| 111 |
+
|
| 112 |
+
# Display assistant response in chat message container
|
| 113 |
+
with st.chat_message("assistant"):
|
| 114 |
+
st.markdown(response)
|
| 115 |
+
|
| 116 |
+
# Add assistant response to chat history
|
| 117 |
+
st.session_state.messages.append({"role": "assistant", "content": response})
|
| 118 |
+
|
| 119 |
else:
|
| 120 |
st.info("π Please log in to view the tasks.")
|