Update app.py
Browse files
app.py
CHANGED
|
@@ -1,23 +1,23 @@
|
|
| 1 |
import streamlit as st
|
| 2 |
-
from
|
| 3 |
from langchain.chains import ConversationChain
|
| 4 |
from langchain.memory import ConversationBufferMemory
|
| 5 |
|
| 6 |
-
# Sidebar for
|
| 7 |
st.sidebar.title("βοΈ Settings")
|
| 8 |
-
api_key = st.sidebar.text_input("Enter your
|
| 9 |
|
| 10 |
st.title("π€ AI Conversational Data Science Tutor")
|
| 11 |
|
| 12 |
if api_key:
|
| 13 |
-
# Initialize model
|
| 14 |
-
llm =
|
| 15 |
-
model="
|
|
|
|
| 16 |
temperature=0.5,
|
| 17 |
-
openai_api_key=api_key
|
| 18 |
)
|
| 19 |
|
| 20 |
-
# Memory for conversation
|
| 21 |
if "memory" not in st.session_state:
|
| 22 |
st.session_state.memory = ConversationBufferMemory(return_messages=True)
|
| 23 |
|
|
@@ -28,15 +28,17 @@ if api_key:
|
|
| 28 |
verbose=False
|
| 29 |
)
|
| 30 |
|
| 31 |
-
#
|
| 32 |
user_input = st.chat_input("Ask a Data Science question...")
|
| 33 |
if user_input:
|
| 34 |
with st.chat_message("user"):
|
| 35 |
st.write(user_input)
|
| 36 |
|
| 37 |
with st.chat_message("assistant"):
|
| 38 |
-
response = conversation.predict(
|
|
|
|
|
|
|
| 39 |
st.write(response)
|
| 40 |
|
| 41 |
else:
|
| 42 |
-
st.warning("π Please enter your
|
|
|
|
| 1 |
import streamlit as st
|
| 2 |
+
from langchain_google_genai import ChatGoogleGenerativeAI
|
| 3 |
from langchain.chains import ConversationChain
|
| 4 |
from langchain.memory import ConversationBufferMemory
|
| 5 |
|
| 6 |
+
# Sidebar for Google API key
|
| 7 |
st.sidebar.title("βοΈ Settings")
|
| 8 |
+
api_key = st.sidebar.text_input("Enter your Google API Key", type="password")
|
| 9 |
|
| 10 |
st.title("π€ AI Conversational Data Science Tutor")
|
| 11 |
|
| 12 |
if api_key:
|
| 13 |
+
# Initialize Gemini model
|
| 14 |
+
llm = ChatGoogleGenerativeAI(
|
| 15 |
+
model="gemini-1.5-pro",
|
| 16 |
+
google_api_key=api_key,
|
| 17 |
temperature=0.5,
|
|
|
|
| 18 |
)
|
| 19 |
|
| 20 |
+
# Memory for conversation
|
| 21 |
if "memory" not in st.session_state:
|
| 22 |
st.session_state.memory = ConversationBufferMemory(return_messages=True)
|
| 23 |
|
|
|
|
| 28 |
verbose=False
|
| 29 |
)
|
| 30 |
|
| 31 |
+
# Chat input
|
| 32 |
user_input = st.chat_input("Ask a Data Science question...")
|
| 33 |
if user_input:
|
| 34 |
with st.chat_message("user"):
|
| 35 |
st.write(user_input)
|
| 36 |
|
| 37 |
with st.chat_message("assistant"):
|
| 38 |
+
response = conversation.predict(
|
| 39 |
+
input=f"You are a Data Science Tutor. Only answer Data Science questions. User asked: {user_input}"
|
| 40 |
+
)
|
| 41 |
st.write(response)
|
| 42 |
|
| 43 |
else:
|
| 44 |
+
st.warning("π Please enter your Google API key in the sidebar to start.")
|