Update app.py
Browse files123456789101112131415161711 unmodified lines29303132333435363738394041426 unmodified lines495051525354553 unmodified lines596061626364653 unmodified lines697071727374757677787980818283848511 unmodified lines979899100101102103104105import osimport torchimport streamlit as stfrom transformers import AutoTokenizer, AutoModelForSeq2SeqLM, pipelinefrom langchain_core.prompts import PromptTemplatefrom langchain.chains import LLMChainfrom langchain_community.llms import HuggingFacePipelinefrom langchain.agents import AgentExecutor, Tool, ZeroShotAgentfrom langchain.memory import ConversationBufferMemoryimport pandas as pdfrom sqlalchemy import create_engineimport smtplibfrom email.mime.text import MIMETextfrom email.mime.multipart import MIMEMultipart# Set up the open-source LLM@st.cache_resource11 unmodified lineslocal_llm = load_model()# Set up the database connectiondb_connection_string = "sqlite:///leads.db" # Replace with your actual database connection stringengine = create_engine(db_connection_string)# Define the tools for the agentdef search_leads(query):df = pd.read_sql(f"SELECT * FROM leads WHERE name LIKE '%{query}%'", engine)return df.to_dict(orient='records')def send_email(to_email, subject, body):# For demo purposes, we'll just print the email details6 unmodified linesTool(name="Search Leads",func=search_leads,description="Useful for searching leads in the database"),Tool(name="Send Email",3 unmodified lines]# Set up the agentprefix = """You are an AI CyberSecurity Program Advisor. Your goal is to engage with leads and get them to book a video call for an in-person sales meeting. You have access to a database of leads and can send emails.You have access to the following tools:"""3 unmodified linesHuman: {human_input}AI: Let's approach this step-by-step:"""prompt = ZeroShotAgent.create_prompt(tools,prefix=prefix,suffix=suffix,input_variables=["human_input", "chat_history"])llm_chain = LLMChain(llm=local_llm, prompt=prompt)memory = ConversationBufferMemory(memory_key="chat_history")agent = ZeroShotAgent(llm_chain=llm_chain, tools=tools, verbose=True)agent_executor = AgentExecutor.from_agent_and_tools(agent=agent, tools=tools, verbose=True, memory=memory)11 unmodified linesst.write(f"No lead found with the name {lead_name}")else:lead = lead_info[0]st.write(f"Lead found: {lead['name']} (Email: {lead['email']})")initial_message = f"Hello {lead['name']}, I'd like to discuss our cybersecurity program with you. Are you available for a quick video call?"if st.button("Engage with Lead"):with st.spinner("AI is generating a response..."):123456789101112131415161711 unmodified lines2930313233343536376 unmodified lines444546474849503 unmodified lines545556575859603 unmodified lines64656667686970717273747576777811 unmodified lines909192939495969798import streamlit as stfrom transformers import AutoTokenizer, AutoModelForSeq2SeqLM, pipelinefrom langchain_core.prompts import PromptTemplatefrom langchain_core.runnables import RunnableSequencefrom langchain_huggingface import HuggingFacePipelinefrom langchain.agents import create_react_agent, AgentExecutor, Toolfrom langchain.memory import ConversationBufferMemory# Mock lead dataLEADS = [{"name": "John Doe", "email": "john@example.com", "company": "TechCorp"},{"name": "Jane Smith", "email": "jane@example.com", "company": "InnoSoft"},{"name": "Bob Johnson", "email": "bob@example.com", "company": "DataTech"},]# Set up the open-source LLM@st.cache_resource11 unmodified lineslocal_llm = load_model()# Define the tools for the agentdef search_leads(query):return [lead for lead in LEADS if query.lower() in lead['name'].lower()]def send_email(to_email, subject, body):# For demo purposes, we'll just print the email details6 unmodified linesTool(name="Search Leads",func=search_leads,description="Useful for searching leads by name"),Tool(name="Send Email",3 unmodified lines]# Set up the agentprefix = """You are an AI CyberSecurity Program Advisor. Your goal is to engage with leads and get them to book a video call for an in-person sales meeting. You have access to a list of leads and can send emails.You have access to the following tools:"""3 unmodified linesHuman: {human_input}AI: Let's approach this step-by-step:"""prompt = PromptTemplate(template=prefix + "{agent_scratchpad}" + suffix,input_variables=["human_input", "chat_history", "agent_scratchpad"])llm_chain = RunnableSequence(prompt, local_llm)memory = ConversationBufferMemory(memory_key="chat_history")agent = create_react_agent(local_llm, tools, prompt)agent_executor = AgentExecutor.from_agent_and_tools(agent=agent, tools=tools, verbose=True, memory=memory)11 unmodified linesst.write(f"No lead found with the name {lead_name}")else:lead = lead_info[0]st.write(f"Lead found: {lead['name']} (Email: {lead['email']}, Company: {lead['company']})")initial_message = f"Hello {lead['name']}, I'd like to discuss our cybersecurity program with {lead['company']}. Are you available for a quick video call?"if st.button("Engage with Lead"):with st.spinner("AI is generating a response..."):
app.py+20-27