Spaces:
Sleeping
Sleeping
File size: 4,849 Bytes
87b46ad |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 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 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 |
import streamlit as st
from crewai import Crew, Agent, Task, Process
from langchain_community.tools import DuckDuckGoSearchRun
#from langchain_openai import ChatOpenAI # Remove OpenAI
from langchain_community.llms import HuggingFaceHub # Import Hugging Face Hub
import datetime
import os
# --- Environment Setup ---
# Make sure to set your HUGGINGFACEHUB_API_TOKEN in your environment variables.
huggingfacehub_api_token = os.environ.get("HUGGINGFACEHUB_API_TOKEN")
# --- Helper Functions ---
def get_date_range():
"""Calculates yesterday's date for the search query."""
today = datetime.date.today()
yesterday = today - datetime.timedelta(days=1)
return yesterday.strftime("%Y-%m-%d")
# --- Agent and Task Definitions ---
def create_ai_news_crew():
"""Creates the CrewAI crew, agents, and tasks."""
search_tool = DuckDuckGoSearchRun()
# Define Agents
researcher = Agent(
role='AI News Researcher',
goal='Find the most recent and relevant AI news articles from yesterday',
backstory="""You are a specialized AI research agent
focused on finding the most relevant and impactful news articles
related to Artificial Intelligence. You excel at using search
tools effectively to find information.""",
verbose=True,
allow_delegation=False,
tools=[search_tool],
llm=HuggingFaceHub(
repo_id="deepseek-ai/DeepSeek-Coder-33B-Instruct", # Use the DeepSeek-Coder model (Instruct version is better for this task)
model_kwargs={"temperature": 0.5, "max_new_tokens": 1024, "repetition_penalty": 1.2}, # Added repetition penalty
huggingfacehub_api_token=huggingfacehub_api_token,
)
)
summarizer = Agent(
role='AI News Summarizer',
goal='Summarize the key news articles and create a concise daily briefing',
backstory="""You are an expert at taking multiple pieces of information
and condensing them into clear, concise, and informative summaries.
You are writing for a busy executive who needs to stay up-to-date
on AI developments quickly.""",
verbose=True,
allow_delegation=False,
llm=HuggingFaceHub(
repo_id="deepseek-ai/DeepSeek-Coder-33B-Instruct", #Use DeepSeek-Coder model
model_kwargs={"temperature": 0.2, "max_new_tokens": 1024, "repetition_penalty": 1.2}, # Lower temp, high rep penalty for concise output
huggingfacehub_api_token=huggingfacehub_api_token,
)
)
# Define Tasks
yesterday_str = get_date_range()
research_task = Task(
description=f"""Find at least 5 relevant news articles about Artificial Intelligence
published on {yesterday_str}. Focus on major breakthroughs,
industry news, ethical considerations, and new applications of AI.
Return the titles and URLs of the most important articles.
""",
agent=researcher
)
summarize_task = Task(
description="""Using the news articles identified, create a daily AI news
briefing. The briefing should be no more than 500 words and should
cover the 3-5 most important AI news items from yesterday. Include
a very brief (1-2 sentence) summary of each item and, if possible, link to the source.
Format the output using markdown for readability.
""",
agent=summarizer
)
# Create Crew
crew = Crew(
agents=[researcher, summarizer],
tasks=[research_task, summarize_task],
verbose=True, # You can set it to 1 or 2 to different level of logs
process=Process.sequential # Tasks are executed sequentially
)
return crew
# --- Streamlit App ---
def main():
"""Main function to run the Streamlit app."""
st.set_page_config(
page_title="AI Daily News Briefing",
page_icon="🤖",
layout="wide"
)
st.title("AI Daily News Briefing 🤖")
st.write("Get a concise summary of the most important AI news from yesterday.")
if st.button("Generate Briefing"):
with st.spinner("Generating your daily AI news briefing..."):
try:
crew = create_ai_news_crew()
result = crew.kickoff() # Start the crew's work
st.subheader("Your AI News Briefing:")
st.markdown(result)
except Exception as e:
st.error(f"An error occurred: {e}")
st.error("Please check your API key and ensure you have set up the environment correctly.")
if __name__ == "__main__":
if not huggingfacehub_api_token:
st.error("HUGGINGFACEHUB_API_TOKEN is not set. Please set it as an environment variable.")
else:
main() |