MujtabaAhmed commited on
Commit
7ac1856
·
verified ·
1 Parent(s): 227598c

Update customquery.py

Browse files
Files changed (1) hide show
  1. customquery.py +56 -55
customquery.py CHANGED
@@ -1,55 +1,56 @@
1
- import streamlit as st
2
- import pandas as pd
3
- import openai
4
-
5
- # Set up OpenAI API
6
- openai.api_key = "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"
7
-
8
- # Function to query ChatGPT with a specific question and dataset context
9
- def query_chatgpt(question, context):
10
- prompt = f"""
11
- Given the following dataset:
12
- {context}
13
-
14
- Answer the following question consisely and write your final calculation:
15
- {question}
16
- """
17
-
18
- prompt2="""You are a teacher who excels in statistics
19
- after recieving the data you have to do calculations and answer the query
20
- asked by the user you are the best in analyzing data in whole world
21
- You do not have to show how you are calculating the answers"""
22
-
23
- response = openai.chat.completions.create(
24
- model="gpt-3.5-turbo",
25
- messages=[
26
- {'role':"system","content":prompt2},
27
- {"role": "user", "content": prompt}
28
- ]
29
- )
30
- return response.choices[0].message.content
31
-
32
- # Streamlit app
33
-
34
- upload_file = st.file_uploader("Upload CSV file with student data", type="csv")
35
-
36
- if upload_file is not None:
37
- # Load the data
38
- df = pd.read_csv(uploaded_file)
39
-
40
- # Display the dataframe
41
- st.write("### Uploaded Data", df)
42
-
43
- # Ask the teacher to input a question
44
- question = st.text_area("Ask a question about the dataset:")
45
-
46
- if st.button("Get Answer"):
47
- # Convert dataframe to a string format
48
- context = df.to_string(index=False)
49
-
50
- # Query ChatGPT
51
- answer = query_chatgpt(question, context)
52
-
53
- # Display the answer
54
- st.write("### Answer from ChatGPT")
55
- st.write(answer)
 
 
1
+ import streamlit as st
2
+ import pandas as pd
3
+ import openai
4
+ import os
5
+
6
+ # Set up OpenAI API
7
+ openai.api_key = os.environ["key"]
8
+
9
+ # Function to query ChatGPT with a specific question and dataset context
10
+ def query_chatgpt(question, context):
11
+ prompt = f"""
12
+ Given the following dataset:
13
+ {context}
14
+
15
+ Answer the following question consisely and write your final calculation:
16
+ {question}
17
+ """
18
+
19
+ prompt2="""You are a teacher who excels in statistics
20
+ after recieving the data you have to do calculations and answer the query
21
+ asked by the user you are the best in analyzing data in whole world
22
+ You do not have to show how you are calculating the answers"""
23
+
24
+ response = openai.chat.completions.create(
25
+ model="gpt-3.5-turbo",
26
+ messages=[
27
+ {'role':"system","content":prompt2},
28
+ {"role": "user", "content": prompt}
29
+ ]
30
+ )
31
+ return response.choices[0].message.content
32
+
33
+ # Streamlit app
34
+
35
+ upload_file = st.file_uploader("Upload CSV file with student data", type="csv")
36
+
37
+ if upload_file is not None:
38
+ # Load the data
39
+ df = pd.read_csv(uploaded_file)
40
+
41
+ # Display the dataframe
42
+ st.write("### Uploaded Data", df)
43
+
44
+ # Ask the teacher to input a question
45
+ question = st.text_area("Ask a question about the dataset:")
46
+
47
+ if st.button("Get Answer"):
48
+ # Convert dataframe to a string format
49
+ context = df.to_string(index=False)
50
+
51
+ # Query ChatGPT
52
+ answer = query_chatgpt(question, context)
53
+
54
+ # Display the answer
55
+ st.write("### Answer from ChatGPT")
56
+ st.write(answer)