Sakil commited on
Commit
bf8db85
·
verified ·
1 Parent(s): 952d904

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +34 -0
app.py ADDED
@@ -0,0 +1,34 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ import pandas as pd
3
+ import logging
4
+ from IPython.display import Markdown, display
5
+ from llama_index.core.query_engine import PandasQueryEngine
6
+ from llama_index.llms.anthropic import Anthropic
7
+
8
+ logging.basicConfig(level=logging.INFO)
9
+
10
+ def main():
11
+ st.title('CSV Data Query Tool')
12
+
13
+ # Upload CSV file
14
+ uploaded_file = st.file_uploader("Upload CSV file", type=['csv'])
15
+ if uploaded_file is not None:
16
+ df = pd.read_csv(uploaded_file)
17
+
18
+ # Input API Key
19
+ api_key = st.text_input("Enter your ANTHROPIC_API_KEY:")
20
+
21
+ # Initialize Anthropic
22
+ if api_key:
23
+ llm = Anthropic(temperature=0.0, model='claude-3-opus-20240229', api_key=api_key)
24
+ query_engine = PandasQueryEngine(df=df, llm=llm, verbose=True)
25
+
26
+ # Input user question
27
+ question = st.text_input("Ask a question about the data:")
28
+ if st.button("Submit"):
29
+ if question:
30
+ response = query_engine.query(question)
31
+ st.markdown(f"**Response:** {response}")
32
+
33
+ if __name__ == "__main__":
34
+ main()