Intellicounsel / app.py
JishnuSetia's picture
Upload 2 files
4fc2b47 verified
raw
history blame
1.72 kB
import streamlit as st
import google.generativeai as genai
import os
from dotenv import load_dotenv
load_dotenv() ## load all our environment variables
os.getenv("GOOGLE_API_KEY")
genai.configure(api_key=os.getenv("GOOGLE_API_KEY"))
st.set_page_config(page_title="Intellicounsel", page_icon="🎓")
st.title("Intellicounsel")
st.text("Your friendly, AI powered, college counsellor")
st.markdown("<hr>", unsafe_allow_html=True)
if "chat_history" not in st.session_state:
st.session_state.chat_history = [("Hello, how can I help you?", "AI")]
user_query = st.chat_input("Type your message here...")
def get_response(user_input):
chat_history_str = "\n".join([f"{message} - {sender}" for message, sender in st.session_state.chat_history])
prompt = f"""Pretend that you are Intellicounsel, a friendly AI-powered college advisor. Your job is to help students with their academics and college apps by providing them with details. You are supposed to answer their queries.
This is the chat history with the user till now:
{chat_history_str}
And this is the user's query:
{user_input}
Return your answer only
"""
model = genai.GenerativeModel('gemini-pro')
response = model.generate_content(prompt)
return response.text
for message, sender in st.session_state.chat_history:
with st.chat_message(sender):
st.write(message)
if user_query is not None and user_query != "":
response = get_response(user_query)
st.session_state.chat_history.append((user_query, "Human"))
st.session_state.chat_history.append((response, "AI"))
with st.chat_message("Human"):
st.write(user_query)
with st.chat_message("AI"):
st.write(response)