File size: 3,106 Bytes
6693486 1c1bdd1 6693486 ab15836 6693486 71625ed 6693486 71625ed 6693486 71625ed 6693486 71625ed | 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 | import streamlit_pills as st_pills
import streamlit as st
import pandas as pd
from pandasai import SmartDataframe
from langchain_groq.chat_models import ChatGroq
from pandasai.llm.openai import OpenAI
def main():
st.set_page_config(layout='wide')
st.title('Conversations with your vulnerability scans')
st.sidebar.image("images/insight.jpg", use_column_width=True)
print("===> ",st.chat_input)
model = st.sidebar.selectbox(
'Step1: Choose a model',
['None', 'gpt','llama3-8b-8192', 'mixtral-8x7b-32768', 'gemma-7b-it'],
)
api_key = st.sidebar.text_input("Step2: Input your API-KEY", value="", type="password")
uploaded_file = st.sidebar.file_uploader("Step3: Upload csv file", type={"csv"})
csvFileObj = open("sample/sample.csv", "r")
st.download_button("Download a Sample CSV", csvFileObj, "sample.csv", "text/csv", key='download-csv')
col1, col2 = st.columns(2)
# LLM object
llm = None
message = None
question_selected = None
query_text = None
with col1:
st.markdown('Chat with the reports (CSV or Excel) and get Insights')
chat = ""
# Input widgets
df_options = ["How many rows are there?", "Display the records related to XSS?", "Display the first 3 record", "Show Pie chart by all severity"]
icons = ["","","",""]
print("==> ",model,uploaded_file)
if uploaded_file and api_key and model is not "None":
# initialize the model obj
if model == 'gpt' and api_key:
llm = OpenAI(api_token=api_key)
elif model == 'llama3-8b-8192' and api_key:
llm = ChatGroq(model="llama3-8b-8192", api_key=api_key)
elif model == 'mixtral-8x7b-32768' and api_key:
llm = ChatGroq(model="llama3-8b-8192", api_key=api_key)
elif model == 'gemma-7b-it' and api_key:
llm = ChatGroq(model="llama3-8b-8192", api_key=api_key)
else:
llm = ChatGroq(model="llama3-8b-8192", api_key=api_key)
# input
question_selected = st_pills.pills("Quick options to try..", df_options, icons)
query_text = st.text_input(placeholder = "Query to the File for continue ...",value=question_selected, label="Place Your Queries")
# App logic to read the uploaded file
df = pd.read_csv(uploaded_file)
print("LLM object ==> ",llm)
dfai = SmartDataframe(df, config={"llm": llm})
else:
st.warning("Please Upload CSV File to continue ...")
with col2:
pass
#message.write(response)
if query_text:
print("QUERY ==> ",query_text)
response = dfai.chat(query_text)
print("RESPONSE TYPE ==> ",type(response))
message = st.chat_message("assistant")
message.write(response)
if type(response) is str:
if ".png" in response:
print("You can draw")
st.image(response)
if __name__ == "__main__":
main()
|