Update app.py
Browse files
app.py
CHANGED
|
@@ -4,7 +4,6 @@ from langchain.memory import ConversationBufferMemory
|
|
| 4 |
from langchain.chains import ConversationChain
|
| 5 |
from langchain_google_genai import ChatGoogleGenerativeAI
|
| 6 |
|
| 7 |
-
# Get Gemini API key from environment variable
|
| 8 |
GEMINI_API_KEY = os.getenv("GEMINI_API_KEY")
|
| 9 |
|
| 10 |
st.set_page_config(page_title="Conversational AI Data Science Tutor", page_icon="🤖")
|
|
@@ -15,13 +14,10 @@ st.write("Ask me any **Data Science** related question!")
|
|
| 15 |
if not GEMINI_API_KEY:
|
| 16 |
st.error("❌ GEMINI_API_KEY not found. Please add it in Hugging Face → Settings → Variables and secrets.")
|
| 17 |
else:
|
| 18 |
-
# Initialize Gemini LLM
|
| 19 |
llm = ChatGoogleGenerativeAI(
|
| 20 |
model="gemini-1.5-pro",
|
| 21 |
google_api_key=GEMINI_API_KEY
|
| 22 |
)
|
| 23 |
-
|
| 24 |
-
# Add memory for conversation awareness
|
| 25 |
memory = ConversationBufferMemory()
|
| 26 |
conversation = ConversationChain(
|
| 27 |
llm=llm,
|
|
@@ -29,23 +25,18 @@ else:
|
|
| 29 |
verbose=False
|
| 30 |
)
|
| 31 |
|
| 32 |
-
|
| 33 |
if "messages" not in st.session_state:
|
| 34 |
st.session_state.messages = []
|
| 35 |
|
| 36 |
-
|
| 37 |
for msg in st.session_state.messages:
|
| 38 |
st.chat_message(msg["role"]).markdown(msg["content"])
|
| 39 |
|
| 40 |
-
|
| 41 |
if prompt := st.chat_input("Ask a data science question..."):
|
| 42 |
-
# Save user message
|
| 43 |
st.session_state.messages.append({"role": "user", "content": prompt})
|
| 44 |
st.chat_message("user").markdown(prompt)
|
| 45 |
-
|
| 46 |
-
# Get model response
|
| 47 |
response = conversation.predict(input=prompt)
|
| 48 |
-
|
| 49 |
-
# Save assistant message
|
| 50 |
st.session_state.messages.append({"role": "assistant", "content": response})
|
| 51 |
st.chat_message("assistant").markdown(response)
|
|
|
|
| 4 |
from langchain.chains import ConversationChain
|
| 5 |
from langchain_google_genai import ChatGoogleGenerativeAI
|
| 6 |
|
|
|
|
| 7 |
GEMINI_API_KEY = os.getenv("GEMINI_API_KEY")
|
| 8 |
|
| 9 |
st.set_page_config(page_title="Conversational AI Data Science Tutor", page_icon="🤖")
|
|
|
|
| 14 |
if not GEMINI_API_KEY:
|
| 15 |
st.error("❌ GEMINI_API_KEY not found. Please add it in Hugging Face → Settings → Variables and secrets.")
|
| 16 |
else:
|
|
|
|
| 17 |
llm = ChatGoogleGenerativeAI(
|
| 18 |
model="gemini-1.5-pro",
|
| 19 |
google_api_key=GEMINI_API_KEY
|
| 20 |
)
|
|
|
|
|
|
|
| 21 |
memory = ConversationBufferMemory()
|
| 22 |
conversation = ConversationChain(
|
| 23 |
llm=llm,
|
|
|
|
| 25 |
verbose=False
|
| 26 |
)
|
| 27 |
|
| 28 |
+
|
| 29 |
if "messages" not in st.session_state:
|
| 30 |
st.session_state.messages = []
|
| 31 |
|
| 32 |
+
|
| 33 |
for msg in st.session_state.messages:
|
| 34 |
st.chat_message(msg["role"]).markdown(msg["content"])
|
| 35 |
|
| 36 |
+
|
| 37 |
if prompt := st.chat_input("Ask a data science question..."):
|
|
|
|
| 38 |
st.session_state.messages.append({"role": "user", "content": prompt})
|
| 39 |
st.chat_message("user").markdown(prompt)
|
|
|
|
|
|
|
| 40 |
response = conversation.predict(input=prompt)
|
|
|
|
|
|
|
| 41 |
st.session_state.messages.append({"role": "assistant", "content": response})
|
| 42 |
st.chat_message("assistant").markdown(response)
|