File size: 1,659 Bytes
7ac1856
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import streamlit as st
import pandas as pd
import openai
import os

# Set up OpenAI API
openai.api_key = os.environ["key"]

# Function to query ChatGPT with a specific question and dataset context
def query_chatgpt(question, context):
    prompt = f"""
    Given the following dataset:
    {context}

    Answer the following question consisely and write your final calculation:
    {question}
    """

    prompt2="""You are a teacher who excels in statistics 
    after recieving the data you have to do calculations and answer the query 
    asked by the user you are  the best in analyzing data in whole world
    You do not have to show how you are calculating the answers"""

    response = openai.chat.completions.create(
        model="gpt-3.5-turbo",
        messages=[
            {'role':"system","content":prompt2},
            {"role": "user", "content": prompt}
        ]
    )
    return response.choices[0].message.content

# Streamlit app

    upload_file = st.file_uploader("Upload CSV file with student data", type="csv")

    if upload_file is not None:
        # Load the data
        df = pd.read_csv(uploaded_file)

        # Display the dataframe
        st.write("### Uploaded Data", df)

        # Ask the teacher to input a question
        question = st.text_area("Ask a question about the dataset:")

        if st.button("Get Answer"):
            # Convert dataframe to a string format
            context = df.to_string(index=False)

            # Query ChatGPT
            answer = query_chatgpt(question, context)

            # Display the answer
            st.write("### Answer from ChatGPT")
            st.write(answer)