Update app.py
Browse files
app.py
CHANGED
|
@@ -1,17 +1,17 @@
|
|
| 1 |
-
import os
|
| 2 |
-
import torch
|
| 3 |
import streamlit as st
|
| 4 |
from transformers import AutoTokenizer, AutoModelForSeq2SeqLM, pipeline
|
| 5 |
from langchain_core.prompts import PromptTemplate
|
| 6 |
-
from
|
| 7 |
-
from
|
| 8 |
-
from langchain.agents import
|
| 9 |
from langchain.memory import ConversationBufferMemory
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
|
|
|
|
|
|
|
| 15 |
|
| 16 |
# Set up the open-source LLM
|
| 17 |
@st.cache_resource
|
|
@@ -29,14 +29,9 @@ def load_model():
|
|
| 29 |
|
| 30 |
local_llm = load_model()
|
| 31 |
|
| 32 |
-
# Set up the database connection
|
| 33 |
-
db_connection_string = "sqlite:///leads.db" # Replace with your actual database connection string
|
| 34 |
-
engine = create_engine(db_connection_string)
|
| 35 |
-
|
| 36 |
# Define the tools for the agent
|
| 37 |
def search_leads(query):
|
| 38 |
-
|
| 39 |
-
return df.to_dict(orient='records')
|
| 40 |
|
| 41 |
def send_email(to_email, subject, body):
|
| 42 |
# For demo purposes, we'll just print the email details
|
|
@@ -49,7 +44,7 @@ tools = [
|
|
| 49 |
Tool(
|
| 50 |
name="Search Leads",
|
| 51 |
func=search_leads,
|
| 52 |
-
description="Useful for searching leads
|
| 53 |
),
|
| 54 |
Tool(
|
| 55 |
name="Send Email",
|
|
@@ -59,7 +54,7 @@ tools = [
|
|
| 59 |
]
|
| 60 |
|
| 61 |
# Set up the agent
|
| 62 |
-
prefix = """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
|
| 63 |
|
| 64 |
You have access to the following tools:"""
|
| 65 |
|
|
@@ -69,17 +64,15 @@ suffix = """Begin!
|
|
| 69 |
Human: {human_input}
|
| 70 |
AI: Let's approach this step-by-step:"""
|
| 71 |
|
| 72 |
-
prompt =
|
| 73 |
-
|
| 74 |
-
|
| 75 |
-
suffix=suffix,
|
| 76 |
-
input_variables=["human_input", "chat_history"]
|
| 77 |
)
|
| 78 |
|
| 79 |
-
llm_chain =
|
| 80 |
memory = ConversationBufferMemory(memory_key="chat_history")
|
| 81 |
|
| 82 |
-
agent =
|
| 83 |
agent_executor = AgentExecutor.from_agent_and_tools(
|
| 84 |
agent=agent, tools=tools, verbose=True, memory=memory
|
| 85 |
)
|
|
@@ -97,9 +90,9 @@ if lead_name:
|
|
| 97 |
st.write(f"No lead found with the name {lead_name}")
|
| 98 |
else:
|
| 99 |
lead = lead_info[0]
|
| 100 |
-
st.write(f"Lead found: {lead['name']} (Email: {lead['email']})")
|
| 101 |
|
| 102 |
-
initial_message = f"Hello {lead['name']}, I'd like to discuss our cybersecurity program with
|
| 103 |
|
| 104 |
if st.button("Engage with Lead"):
|
| 105 |
with st.spinner("AI is generating a response..."):
|
|
|
|
|
|
|
|
|
|
| 1 |
import streamlit as st
|
| 2 |
from transformers import AutoTokenizer, AutoModelForSeq2SeqLM, pipeline
|
| 3 |
from langchain_core.prompts import PromptTemplate
|
| 4 |
+
from langchain_core.runnables import RunnableSequence
|
| 5 |
+
from langchain_huggingface import HuggingFacePipeline
|
| 6 |
+
from langchain.agents import create_react_agent, AgentExecutor, Tool
|
| 7 |
from langchain.memory import ConversationBufferMemory
|
| 8 |
+
|
| 9 |
+
# Mock lead data
|
| 10 |
+
LEADS = [
|
| 11 |
+
{"name": "John Doe", "email": "john@example.com", "company": "TechCorp"},
|
| 12 |
+
{"name": "Jane Smith", "email": "jane@example.com", "company": "InnoSoft"},
|
| 13 |
+
{"name": "Bob Johnson", "email": "bob@example.com", "company": "DataTech"},
|
| 14 |
+
]
|
| 15 |
|
| 16 |
# Set up the open-source LLM
|
| 17 |
@st.cache_resource
|
|
|
|
| 29 |
|
| 30 |
local_llm = load_model()
|
| 31 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 32 |
# Define the tools for the agent
|
| 33 |
def search_leads(query):
|
| 34 |
+
return [lead for lead in LEADS if query.lower() in lead['name'].lower()]
|
|
|
|
| 35 |
|
| 36 |
def send_email(to_email, subject, body):
|
| 37 |
# For demo purposes, we'll just print the email details
|
|
|
|
| 44 |
Tool(
|
| 45 |
name="Search Leads",
|
| 46 |
func=search_leads,
|
| 47 |
+
description="Useful for searching leads by name"
|
| 48 |
),
|
| 49 |
Tool(
|
| 50 |
name="Send Email",
|
|
|
|
| 54 |
]
|
| 55 |
|
| 56 |
# Set up the agent
|
| 57 |
+
prefix = """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.
|
| 58 |
|
| 59 |
You have access to the following tools:"""
|
| 60 |
|
|
|
|
| 64 |
Human: {human_input}
|
| 65 |
AI: Let's approach this step-by-step:"""
|
| 66 |
|
| 67 |
+
prompt = PromptTemplate(
|
| 68 |
+
template=prefix + "{agent_scratchpad}" + suffix,
|
| 69 |
+
input_variables=["human_input", "chat_history", "agent_scratchpad"]
|
|
|
|
|
|
|
| 70 |
)
|
| 71 |
|
| 72 |
+
llm_chain = RunnableSequence(prompt, local_llm)
|
| 73 |
memory = ConversationBufferMemory(memory_key="chat_history")
|
| 74 |
|
| 75 |
+
agent = create_react_agent(local_llm, tools, prompt)
|
| 76 |
agent_executor = AgentExecutor.from_agent_and_tools(
|
| 77 |
agent=agent, tools=tools, verbose=True, memory=memory
|
| 78 |
)
|
|
|
|
| 90 |
st.write(f"No lead found with the name {lead_name}")
|
| 91 |
else:
|
| 92 |
lead = lead_info[0]
|
| 93 |
+
st.write(f"Lead found: {lead['name']} (Email: {lead['email']}, Company: {lead['company']})")
|
| 94 |
|
| 95 |
+
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?"
|
| 96 |
|
| 97 |
if st.button("Engage with Lead"):
|
| 98 |
with st.spinner("AI is generating a response..."):
|