Upload utils.py
Browse files
utils.py
ADDED
@@ -0,0 +1,44 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import whisper
|
2 |
+
from langchain.llms import OpenAI
|
3 |
+
from langchain.agents import initialize_agent
|
4 |
+
from langchain.agents.agent_toolkits import ZapierToolkit
|
5 |
+
from langchain.utilities.zapier import ZapierNLAWrapper
|
6 |
+
from langchain.agents import initialize_agent, load_tools, AgentType
|
7 |
+
import os
|
8 |
+
|
9 |
+
# get from https://platform.openai.com/
|
10 |
+
os.environ["OPENAI_API_KEY"] = "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"
|
11 |
+
|
12 |
+
# get from https://nla.zapier.com/docs/authentication/ & https://actions.zapier.com/credentials/ after logging in):
|
13 |
+
os.environ["ZAPIER_NLA_API_KEY"] = "sk-ak-tOoi6NEUPQKcLt9PqemVcaR7Vb"
|
14 |
+
|
15 |
+
|
16 |
+
def email_summary(file):
|
17 |
+
|
18 |
+
|
19 |
+
# large language model
|
20 |
+
llm = OpenAI(temperature=0)
|
21 |
+
|
22 |
+
# Initializing zapier
|
23 |
+
zapier = ZapierNLAWrapper()
|
24 |
+
toolkit = ZapierToolkit.from_zapier_nla_wrapper(zapier)
|
25 |
+
|
26 |
+
# The agent used here is a "zero-shot-react-description" agent.
|
27 |
+
# Zero-shot means the agent functions on the current action only — it has no memory.
|
28 |
+
# It uses the ReAct framework to decide which tool to use, based solely on the tool's description.
|
29 |
+
agent = initialize_agent(toolkit.get_tools(), llm, agent="zero-shot-react-description", verbose=True)
|
30 |
+
|
31 |
+
|
32 |
+
# specify a model, here its BASE
|
33 |
+
model = whisper.load_model("base")
|
34 |
+
|
35 |
+
|
36 |
+
|
37 |
+
# transcribe audio file
|
38 |
+
result = model.transcribe(file)
|
39 |
+
print(result["text"])
|
40 |
+
|
41 |
+
# Send email using zapier
|
42 |
+
agent.run("Send an Email to barkha.verma@crossml.com via gmail summarizing the following text provided below : "+result["text"])
|
43 |
+
|
44 |
+
|