Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -1,14 +1,12 @@
|
|
1 |
import streamlit as st
|
2 |
from crewai import Crew, Agent, Task, Process
|
|
|
3 |
from langchain_community.tools import DuckDuckGoSearchRun
|
4 |
-
|
5 |
-
from langchain_community.llms import HuggingFaceHub # Import Hugging Face Hub
|
6 |
import datetime
|
7 |
import os
|
8 |
|
9 |
# --- Environment Setup ---
|
10 |
-
# Make sure to set your HUGGINGFACEHUB_API_TOKEN in your environment variables.
|
11 |
-
|
12 |
huggingfacehub_api_token = os.environ.get("HUGGINGFACEHUB_API_TOKEN")
|
13 |
|
14 |
|
@@ -21,13 +19,19 @@ def get_date_range():
|
|
21 |
return yesterday.strftime("%Y-%m-%d")
|
22 |
|
23 |
|
24 |
-
|
25 |
# --- Agent and Task Definitions ---
|
26 |
|
27 |
def create_ai_news_crew():
|
28 |
"""Creates the CrewAI crew, agents, and tasks."""
|
29 |
|
30 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
31 |
|
32 |
# Define Agents
|
33 |
researcher = Agent(
|
@@ -39,10 +43,10 @@ def create_ai_news_crew():
|
|
39 |
tools effectively to find information.""",
|
40 |
verbose=True,
|
41 |
allow_delegation=False,
|
42 |
-
tools=[search_tool],
|
43 |
llm=HuggingFaceHub(
|
44 |
-
repo_id="deepseek-ai/DeepSeek-Coder-33B-Instruct",
|
45 |
-
model_kwargs={"temperature": 0.5, "max_new_tokens": 1024, "repetition_penalty": 1.2},
|
46 |
huggingfacehub_api_token=huggingfacehub_api_token,
|
47 |
)
|
48 |
)
|
@@ -57,12 +61,12 @@ def create_ai_news_crew():
|
|
57 |
verbose=True,
|
58 |
allow_delegation=False,
|
59 |
llm=HuggingFaceHub(
|
60 |
-
repo_id="deepseek-ai/DeepSeek-Coder-33B-Instruct",
|
61 |
-
model_kwargs={"temperature": 0.2, "max_new_tokens": 1024, "repetition_penalty": 1.2},
|
62 |
huggingfacehub_api_token=huggingfacehub_api_token,
|
63 |
)
|
64 |
)
|
65 |
-
|
66 |
# Define Tasks
|
67 |
yesterday_str = get_date_range()
|
68 |
research_task = Task(
|
@@ -73,29 +77,27 @@ def create_ai_news_crew():
|
|
73 |
""",
|
74 |
agent=researcher
|
75 |
)
|
76 |
-
|
77 |
summarize_task = Task(
|
78 |
-
|
79 |
briefing. The briefing should be no more than 500 words and should
|
80 |
cover the 3-5 most important AI news items from yesterday. Include
|
81 |
a very brief (1-2 sentence) summary of each item and, if possible, link to the source.
|
82 |
Format the output using markdown for readability.
|
83 |
""",
|
84 |
-
|
85 |
)
|
86 |
|
87 |
# Create Crew
|
88 |
crew = Crew(
|
89 |
agents=[researcher, summarizer],
|
90 |
tasks=[research_task, summarize_task],
|
91 |
-
verbose=True,
|
92 |
-
process=Process.sequential
|
93 |
)
|
94 |
return crew
|
95 |
|
96 |
|
97 |
-
|
98 |
-
|
99 |
# --- Streamlit App ---
|
100 |
|
101 |
def main():
|
@@ -114,7 +116,7 @@ def main():
|
|
114 |
with st.spinner("Generating your daily AI news briefing..."):
|
115 |
try:
|
116 |
crew = create_ai_news_crew()
|
117 |
-
result = crew.kickoff()
|
118 |
st.subheader("Your AI News Briefing:")
|
119 |
st.markdown(result)
|
120 |
|
@@ -123,7 +125,6 @@ def main():
|
|
123 |
st.error("Please check your API key and ensure you have set up the environment correctly.")
|
124 |
|
125 |
|
126 |
-
|
127 |
if __name__ == "__main__":
|
128 |
if not huggingfacehub_api_token:
|
129 |
st.error("HUGGINGFACEHUB_API_TOKEN is not set. Please set it as an environment variable.")
|
|
|
1 |
import streamlit as st
|
2 |
from crewai import Crew, Agent, Task, Process
|
3 |
+
from langchain_core.tools import Tool # Import Tool from langchain_core.tools
|
4 |
from langchain_community.tools import DuckDuckGoSearchRun
|
5 |
+
from langchain_community.llms import HuggingFaceHub
|
|
|
6 |
import datetime
|
7 |
import os
|
8 |
|
9 |
# --- Environment Setup ---
|
|
|
|
|
10 |
huggingfacehub_api_token = os.environ.get("HUGGINGFACEHUB_API_TOKEN")
|
11 |
|
12 |
|
|
|
19 |
return yesterday.strftime("%Y-%m-%d")
|
20 |
|
21 |
|
|
|
22 |
# --- Agent and Task Definitions ---
|
23 |
|
24 |
def create_ai_news_crew():
|
25 |
"""Creates the CrewAI crew, agents, and tasks."""
|
26 |
|
27 |
+
search_tool_instance = DuckDuckGoSearchRun()
|
28 |
+
|
29 |
+
# Wrap the DuckDuckGoSearchRun instance with the Tool class.
|
30 |
+
search_tool = Tool(
|
31 |
+
name="DuckDuckGo Search",
|
32 |
+
func=search_tool_instance.run,
|
33 |
+
description="Useful for searching the web for recent AI news articles.",
|
34 |
+
)
|
35 |
|
36 |
# Define Agents
|
37 |
researcher = Agent(
|
|
|
43 |
tools effectively to find information.""",
|
44 |
verbose=True,
|
45 |
allow_delegation=False,
|
46 |
+
tools=[search_tool], # Pass the wrapped tool
|
47 |
llm=HuggingFaceHub(
|
48 |
+
repo_id="deepseek-ai/DeepSeek-Coder-33B-Instruct",
|
49 |
+
model_kwargs={"temperature": 0.5, "max_new_tokens": 1024, "repetition_penalty": 1.2},
|
50 |
huggingfacehub_api_token=huggingfacehub_api_token,
|
51 |
)
|
52 |
)
|
|
|
61 |
verbose=True,
|
62 |
allow_delegation=False,
|
63 |
llm=HuggingFaceHub(
|
64 |
+
repo_id="deepseek-ai/DeepSeek-Coder-33B-Instruct",
|
65 |
+
model_kwargs={"temperature": 0.2, "max_new_tokens": 1024, "repetition_penalty": 1.2},
|
66 |
huggingfacehub_api_token=huggingfacehub_api_token,
|
67 |
)
|
68 |
)
|
69 |
+
|
70 |
# Define Tasks
|
71 |
yesterday_str = get_date_range()
|
72 |
research_task = Task(
|
|
|
77 |
""",
|
78 |
agent=researcher
|
79 |
)
|
80 |
+
|
81 |
summarize_task = Task(
|
82 |
+
description="""Using the news articles identified, create a daily AI news
|
83 |
briefing. The briefing should be no more than 500 words and should
|
84 |
cover the 3-5 most important AI news items from yesterday. Include
|
85 |
a very brief (1-2 sentence) summary of each item and, if possible, link to the source.
|
86 |
Format the output using markdown for readability.
|
87 |
""",
|
88 |
+
agent=summarizer
|
89 |
)
|
90 |
|
91 |
# Create Crew
|
92 |
crew = Crew(
|
93 |
agents=[researcher, summarizer],
|
94 |
tasks=[research_task, summarize_task],
|
95 |
+
verbose=True,
|
96 |
+
process=Process.sequential
|
97 |
)
|
98 |
return crew
|
99 |
|
100 |
|
|
|
|
|
101 |
# --- Streamlit App ---
|
102 |
|
103 |
def main():
|
|
|
116 |
with st.spinner("Generating your daily AI news briefing..."):
|
117 |
try:
|
118 |
crew = create_ai_news_crew()
|
119 |
+
result = crew.kickoff()
|
120 |
st.subheader("Your AI News Briefing:")
|
121 |
st.markdown(result)
|
122 |
|
|
|
125 |
st.error("Please check your API key and ensure you have set up the environment correctly.")
|
126 |
|
127 |
|
|
|
128 |
if __name__ == "__main__":
|
129 |
if not huggingfacehub_api_token:
|
130 |
st.error("HUGGINGFACEHUB_API_TOKEN is not set. Please set it as an environment variable.")
|