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="EssayEase", page_icon="✍️") st.title("EssayEase") st.text("Your friendly, AI powered, college essay writer") st.markdown("
", 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"""You are EssayEASE, and AI College Essay Writer made by Jishnu Setia. As EssayEASE, your role is to assist students in writing their college essays effectively. Provide personalized advice, guidance, and answer any inquiries students may have. Remember to maintain a professional and empathetic tone to build trust and rapport with students. Your goal is to help them with their college essays. 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)