Spaces:
Build error
Build error
Update app.py
Browse files
app.py
CHANGED
|
@@ -7,12 +7,12 @@ import os
|
|
| 7 |
from dotenv import load_dotenv
|
| 8 |
|
| 9 |
# ✅ Load API Key from Environment Variables or User Input
|
| 10 |
-
load_dotenv()
|
| 11 |
api_key = os.getenv("GOOGLE_API_KEY")
|
| 12 |
|
| 13 |
# If .env file is missing or API key is not found, ask the user to input it
|
| 14 |
if not api_key:
|
| 15 |
-
st.warning("🔑 Google API key not found in .env file. Please enter your API key below.")
|
| 16 |
api_key = st.text_input("Enter your Google API Key:", type="password")
|
| 17 |
|
| 18 |
if not api_key:
|
|
@@ -61,7 +61,10 @@ if "messages" not in st.session_state:
|
|
| 61 |
# Display previous messages
|
| 62 |
for message in st.session_state.messages:
|
| 63 |
with st.chat_message(message["role"]):
|
| 64 |
-
|
|
|
|
|
|
|
|
|
|
| 65 |
|
| 66 |
# User Input
|
| 67 |
user_input = st.chat_input("Ask me a data science question (e.g., What is linear regression?)...")
|
|
@@ -78,10 +81,12 @@ if user_input:
|
|
| 78 |
response = conversation.predict(input=user_input)
|
| 79 |
except Exception as e:
|
| 80 |
response = f"An error occurred: {str(e)}"
|
|
|
|
|
|
|
| 81 |
|
| 82 |
# Display AI response
|
| 83 |
with st.chat_message("assistant"):
|
| 84 |
-
st.markdown(response)
|
| 85 |
|
| 86 |
# Store AI message
|
| 87 |
st.session_state.messages.append({"role": "assistant", "content": response})
|
|
@@ -91,4 +96,4 @@ if st.button("Reset Chat"):
|
|
| 91 |
if st.confirm("Are you sure you want to reset the chat?"):
|
| 92 |
st.session_state.messages = []
|
| 93 |
memory.clear()
|
| 94 |
-
st.
|
|
|
|
| 7 |
from dotenv import load_dotenv
|
| 8 |
|
| 9 |
# ✅ Load API Key from Environment Variables or User Input
|
| 10 |
+
load_dotenv()
|
| 11 |
api_key = os.getenv("GOOGLE_API_KEY")
|
| 12 |
|
| 13 |
# If .env file is missing or API key is not found, ask the user to input it
|
| 14 |
if not api_key:
|
| 15 |
+
st.warning("🔑 Google API key not found in `.env` file. Please enter your API key below.")
|
| 16 |
api_key = st.text_input("Enter your Google API Key:", type="password")
|
| 17 |
|
| 18 |
if not api_key:
|
|
|
|
| 61 |
# Display previous messages
|
| 62 |
for message in st.session_state.messages:
|
| 63 |
with st.chat_message(message["role"]):
|
| 64 |
+
if message["role"] == "assistant":
|
| 65 |
+
st.markdown(f"```python\n{message['content']}\n```") # Format AI responses
|
| 66 |
+
else:
|
| 67 |
+
st.markdown(message["content"])
|
| 68 |
|
| 69 |
# User Input
|
| 70 |
user_input = st.chat_input("Ask me a data science question (e.g., What is linear regression?)...")
|
|
|
|
| 81 |
response = conversation.predict(input=user_input)
|
| 82 |
except Exception as e:
|
| 83 |
response = f"An error occurred: {str(e)}"
|
| 84 |
+
with st.expander("See error details"):
|
| 85 |
+
st.code(str(e))
|
| 86 |
|
| 87 |
# Display AI response
|
| 88 |
with st.chat_message("assistant"):
|
| 89 |
+
st.markdown(f"```python\n{response}\n```")
|
| 90 |
|
| 91 |
# Store AI message
|
| 92 |
st.session_state.messages.append({"role": "assistant", "content": response})
|
|
|
|
| 96 |
if st.confirm("Are you sure you want to reset the chat?"):
|
| 97 |
st.session_state.messages = []
|
| 98 |
memory.clear()
|
| 99 |
+
st.rerun()
|