Update app.py
Browse files
app.py
CHANGED
@@ -17,7 +17,7 @@ uploaded_file = st.sidebar.file_uploader("Choose a CSV file", type="csv")
|
|
17 |
if uploaded_file is not None:
|
18 |
st.session_state["df"] = pd.read_csv(uploaded_file)
|
19 |
|
20 |
-
#
|
21 |
def ask_openai(prompt):
|
22 |
try:
|
23 |
response = openai.ChatCompletion.create(
|
@@ -27,17 +27,18 @@ def ask_openai(prompt):
|
|
27 |
)
|
28 |
return response.choices[0].message["content"]
|
29 |
except Exception as e:
|
30 |
-
|
31 |
-
return "
|
32 |
-
|
33 |
-
#
|
34 |
-
|
35 |
-
|
36 |
-
|
37 |
-
if
|
38 |
-
st.
|
39 |
-
|
40 |
-
|
41 |
-
|
42 |
-
|
43 |
-
|
|
|
|
17 |
if uploaded_file is not None:
|
18 |
st.session_state["df"] = pd.read_csv(uploaded_file)
|
19 |
|
20 |
+
# Function to generate a response from OpenAI's chat model
|
21 |
def ask_openai(prompt):
|
22 |
try:
|
23 |
response = openai.ChatCompletion.create(
|
|
|
27 |
)
|
28 |
return response.choices[0].message["content"]
|
29 |
except Exception as e:
|
30 |
+
st.error(f"Error in generating response: {e}")
|
31 |
+
return "I encountered an error. Please try again."
|
32 |
+
|
33 |
+
# Input for new messages
|
34 |
+
user_input = st.text_input("Ask me anything:", key="chat_input")
|
35 |
+
|
36 |
+
# Process input on submission
|
37 |
+
if user_input:
|
38 |
+
with st.chat_message("user"):
|
39 |
+
st.write(user_input)
|
40 |
+
|
41 |
+
# Generate and display response
|
42 |
+
ai_response = ask_openai(user_input)
|
43 |
+
with st.chat_message("assistant"):
|
44 |
+
st.write(ai_response)
|