File size: 1,328 Bytes
bf8db85
 
 
537bc8d
bf8db85
 
 
 
 
 
 
537bc8d
52fa9a3
 
 
 
 
 
bf8db85
 
 
 
537bc8d
bf8db85
 
537bc8d
bf8db85
 
 
 
537bc8d
b14297b
52fa9a3
b14297b
 
 
 
0cad2e5
bf8db85
 
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
import streamlit as st
import pandas as pd
import logging
from IPython.display import Markdown, display
from llama_index.core.query_engine import PandasQueryEngine
from llama_index.llms.anthropic import Anthropic

logging.basicConfig(level=logging.INFO)

def main():
    st.title('CSV Data Query Tool')

    # Description
    st.write("""
    This app helps you query tabular data using natural language. 
    Upload a CSV file, enter your ANTHROPIC_API_KEY, ask a question about the data, and get a response!
    """)

    # Upload CSV file
    uploaded_file = st.file_uploader("Upload CSV file", type=['csv'])
    if uploaded_file is not None:
        df = pd.read_csv(uploaded_file)

        # Input API Key
        api_key = st.text_input("Enter your ANTHROPIC_API_KEY:")

        # Initialize Anthropic
        if api_key:
            llm = Anthropic(temperature=0.0, model='claude-3-opus-20240229', api_key=api_key)
            query_engine = PandasQueryEngine(df=df, llm=llm, verbose=True)

            # Input user question
            question = st.text_input("Ask a question about the data:")
            if st.button("Submit"):
                if question:
                    response = query_engine.query(question)
                    st.markdown(f"**Response:** {response}")

if __name__ == "__main__":
    main()