aiscientist commited on
Commit
2bb5933
β€’
1 Parent(s): 10fd61d

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +66 -0
app.py ADDED
@@ -0,0 +1,66 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from dotenv import load_dotenv
2
+ import streamlit as st
3
+ from langchain_experimental.agents import create_csv_agent
4
+ from langchain.llms import HuggingFaceHub
5
+
6
+ load_dotenv()
7
+
8
+ def main():
9
+ st.set_page_config(
10
+ page_title= "QnA with CSV",
11
+ page_icon=":robot_face:",
12
+ layout="wide"
13
+ )
14
+
15
+ st.title("QnA with CSV πŸ€–")
16
+ user_csv = st.file_uploader(label = "", type= "csv")
17
+ if not user_csv:
18
+ st.warning("Please Upload your CSV file 🚨")
19
+
20
+ llm = HuggingFaceHub(
21
+ repo_id = "mistralai/Mistral-7B-Instruct-v0.2",
22
+ model_kwargs = {
23
+ 'max_new_tokens': 249,
24
+ 'temperature': 0.3,
25
+ }
26
+ )
27
+ user_input = st.text_input("Ask your Question about CSV files", disabled= not user_csv)
28
+
29
+ with st.sidebar:
30
+ st.subheader("Example Questions:")
31
+ example_questions = [
32
+ "What is the total number of rows in the CSV?",
33
+ "Can you show me the first 5 rows of the CSV?",
34
+ "What are the column names in the CSV?",
35
+ "How many columns does the CSV have?",
36
+ "What is the data type of a specific column in the CSV?",
37
+ "Can you provide a summary statistics for the numerical columns?",
38
+ "Are there any missing values in the CSV?",
39
+ "Can you filter the data based on a specific condition?",
40
+ "What is the average value of a numerical column?",
41
+ ]
42
+
43
+ selected_example = st.selectbox("Select an example question:", example_questions, disabled= not user_csv)
44
+
45
+ if not user_csv:
46
+ st.warning("Please Upload your CSV file 🚨")
47
+
48
+ if st.button("Use Selected Example"):
49
+ user_input = selected_example
50
+
51
+ if user_csv is not None:
52
+ agent = create_csv_agent(
53
+ llm = llm,
54
+ path = user_csv,
55
+ verbose = True,
56
+ handle_parsing_errors=True
57
+ )
58
+
59
+ if user_input is not None and user_input != "":
60
+ st.write("User:", user_input)
61
+ with st.spinner("Processing..."):
62
+ response = agent.run(user_input)
63
+ st.write("Bot:", response)
64
+
65
+ if __name__ == "__main__":
66
+ main()