Spaces:
Sleeping
Sleeping
add secret key
Browse files- Summarization.py +51 -50
Summarization.py
CHANGED
|
@@ -1,51 +1,52 @@
|
|
| 1 |
-
# Warning control
|
| 2 |
-
import warnings
|
| 3 |
-
warnings.filterwarnings('ignore')
|
| 4 |
-
|
| 5 |
-
from typing import List
|
| 6 |
-
import json
|
| 7 |
-
from pydantic import BaseModel
|
| 8 |
-
# from langchain_community.llms import HuggingFaceHub
|
| 9 |
-
from langchain_huggingface import HuggingFaceEndpoint
|
| 10 |
-
from crewai import Agent, Task, Crew
|
| 11 |
-
|
| 12 |
-
import os
|
| 13 |
-
from dotenv import load_dotenv, find_dotenv
|
| 14 |
-
_ = load_dotenv(find_dotenv()) # read local .env file
|
| 15 |
-
hf_api_key = os.environ['HF_API_KEY']
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
"
|
| 29 |
-
|
| 30 |
-
|
| 31 |
-
|
| 32 |
-
|
| 33 |
-
|
| 34 |
-
|
| 35 |
-
|
| 36 |
-
|
| 37 |
-
|
| 38 |
-
|
| 39 |
-
|
| 40 |
-
|
| 41 |
-
|
| 42 |
-
|
| 43 |
-
|
| 44 |
-
|
| 45 |
-
|
| 46 |
-
|
| 47 |
-
|
| 48 |
-
|
| 49 |
-
|
| 50 |
-
|
|
|
|
| 51 |
return result
|
|
|
|
| 1 |
+
# Warning control
|
| 2 |
+
import warnings
|
| 3 |
+
warnings.filterwarnings('ignore')
|
| 4 |
+
|
| 5 |
+
from typing import List
|
| 6 |
+
import json
|
| 7 |
+
from pydantic import BaseModel
|
| 8 |
+
# from langchain_community.llms import HuggingFaceHub
|
| 9 |
+
from langchain_huggingface import HuggingFaceEndpoint
|
| 10 |
+
from crewai import Agent, Task, Crew
|
| 11 |
+
|
| 12 |
+
import os
|
| 13 |
+
from dotenv import load_dotenv, find_dotenv
|
| 14 |
+
_ = load_dotenv(find_dotenv()) # read local .env file
|
| 15 |
+
# hf_api_key = os.environ['HF_API_KEY']
|
| 16 |
+
hf_api_key = os.getenv('HF_API_KEY')
|
| 17 |
+
|
| 18 |
+
llm = HuggingFaceEndpoint(
|
| 19 |
+
repo_id="HuggingFaceH4/zephyr-7b-beta",
|
| 20 |
+
huggingfacehub_api_token=hf_api_key,
|
| 21 |
+
task="text-generation"
|
| 22 |
+
)
|
| 23 |
+
|
| 24 |
+
editor = Agent(
|
| 25 |
+
role="Editor",
|
| 26 |
+
goal="Extract the summary of user requirements based on the chat between user and Graphic designer. Chat: {chat}",
|
| 27 |
+
backstory="You're working as an Editor"
|
| 28 |
+
"You are provided with chat between user and graphic designer. Chat: {chat}."
|
| 29 |
+
"Extract the summary of user requirements from the chat",
|
| 30 |
+
llm=llm,
|
| 31 |
+
allow_delegation=False,
|
| 32 |
+
verbose=False
|
| 33 |
+
)
|
| 34 |
+
|
| 35 |
+
|
| 36 |
+
summary = Task(
|
| 37 |
+
description=(
|
| 38 |
+
"Provide the summary of user requirements based on the chat between user and Graphic designer. Chat: {chat}"
|
| 39 |
+
),
|
| 40 |
+
expected_output="Summary of user requirements. output only summary",
|
| 41 |
+
agent=editor,
|
| 42 |
+
)
|
| 43 |
+
|
| 44 |
+
crew = Crew(
|
| 45 |
+
agents=[editor],
|
| 46 |
+
tasks=[summary],
|
| 47 |
+
verbose=False
|
| 48 |
+
)
|
| 49 |
+
|
| 50 |
+
def Summarizer(chat, userDefinedQuestions=None):
|
| 51 |
+
result = crew.kickoff(inputs={"chat": chat})
|
| 52 |
return result
|