Create app.py
Browse filesConversations with your vulnerability scans app
app.py
ADDED
|
@@ -0,0 +1,73 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import streamlit_pills as st_pills
|
| 2 |
+
import streamlit as st
|
| 3 |
+
import pandas as pd
|
| 4 |
+
from pandasai import SmartDataframe
|
| 5 |
+
from langchain_groq.chat_models import ChatGroq
|
| 6 |
+
from pandasai.llm.openai import OpenAI
|
| 7 |
+
|
| 8 |
+
|
| 9 |
+
def main():
|
| 10 |
+
st.set_page_config(layout='wide')
|
| 11 |
+
st.title('Conversations with your vulnerability scans')
|
| 12 |
+
st.sidebar.image("./insight.jpg", use_column_width=True)
|
| 13 |
+
print("===> ",st.chat_input)
|
| 14 |
+
model = st.sidebar.selectbox(
|
| 15 |
+
'Step1: Choose a model',
|
| 16 |
+
['None', 'gpt','llama3-8b-8192', 'mixtral-8x7b-32768', 'gemma-7b-it'],
|
| 17 |
+
)
|
| 18 |
+
api_key = st.sidebar.text_input("Step2: Input your API-KEY", value="", type="password")
|
| 19 |
+
uploaded_file = st.sidebar.file_uploader("Step3: Upload csv file", type={"csv"})
|
| 20 |
+
csvFileObj = open("VulnR.csv", "r")
|
| 21 |
+
st.download_button("Download a Sample CSV", csvFileObj, "sample.csv", "text/csv", key='download-csv')
|
| 22 |
+
|
| 23 |
+
col1, col2 = st.columns(2)
|
| 24 |
+
# LLM object
|
| 25 |
+
llm = None
|
| 26 |
+
message = None
|
| 27 |
+
question_selected = None
|
| 28 |
+
query_text = None
|
| 29 |
+
# model = None
|
| 30 |
+
# api_key = None
|
| 31 |
+
with col1:
|
| 32 |
+
st.markdown('Chat with the reports (CSV or Excel) and get Insights')
|
| 33 |
+
chat = ""
|
| 34 |
+
# Input widgets
|
| 35 |
+
df_options = ["How many rows are there?", "Display the records related to XSS?", "Display the first 3 record", "Show Pie chart by all severity"]
|
| 36 |
+
icons = ["","","",""]
|
| 37 |
+
if uploaded_file and model and api_key:
|
| 38 |
+
# initialize the model obj
|
| 39 |
+
if model == 'gpt' and api_key:
|
| 40 |
+
llm = OpenAI(api_token=api_key)
|
| 41 |
+
else:
|
| 42 |
+
llm = ChatGroq(model="llama3-8b-8192", api_key=api_key)
|
| 43 |
+
# input
|
| 44 |
+
question_selected = st_pills.pills("Quick options to try..", df_options, icons)
|
| 45 |
+
query_text = st.text_input(placeholder = "Query to the File for continue ...",value=question_selected, label="Place Your Queries")
|
| 46 |
+
|
| 47 |
+
# App logic to read the uploaded file
|
| 48 |
+
df = pd.read_csv(uploaded_file)
|
| 49 |
+
print("LLM object ==> ",llm)
|
| 50 |
+
dfai = SmartDataframe(df, config={"llm": llm})
|
| 51 |
+
else:
|
| 52 |
+
st.warning("Please Upload CSV File to continue ...")
|
| 53 |
+
|
| 54 |
+
#future plan
|
| 55 |
+
with col2:
|
| 56 |
+
pass
|
| 57 |
+
|
| 58 |
+
#message.write(response)
|
| 59 |
+
if query_text:
|
| 60 |
+
print("QUERY ==> ",query_text)
|
| 61 |
+
response = dfai.chat(query_text)
|
| 62 |
+
print("RESPONSE TYPE ==> ",type(response))
|
| 63 |
+
message = st.chat_message("assistant")
|
| 64 |
+
message.write(response)
|
| 65 |
+
if type(response) is str:
|
| 66 |
+
if ".png" in response:
|
| 67 |
+
print("You can draw")
|
| 68 |
+
st.image(response)
|
| 69 |
+
|
| 70 |
+
|
| 71 |
+
|
| 72 |
+
if __name__ == "__main__":
|
| 73 |
+
main()
|