Web_Roaster / app.py
BroBro87's picture
Update app.py
1dbdead verified
raw
history blame
1.82 kB
import gradio as gr
from composio_crewai import ComposioToolSet, App, Action
from crewai import Agent, Task, Crew, Process
from langchain_openai import ChatOpenAI
from dotenv import load_dotenv
import os
load_dotenv()
llm = ChatOpenAI(model="gpt-4o")
toolset = ComposioToolSet()
tools = toolset.get_tools(apps=[App.SERPAPI])
def find_hackernews_posts(message,history):
profile = message
hacnews_agent = Agent(
role="Technical Researcher",
goal="Find the best technical posts on Hackernews",
backstory="You are a technical person who loves reading Hackernews and looking for technical posts. You spend all your time looking for interesting posts of the day.",
llm=llm,
tools=tools
)
hacnews_task = Task(
description=f"""
Use the serp tool to search for the user's twitter profile of name {profile} to read his bio,
and then scrape it. Based on his bio, find good technical hackernews posts suited to his bio.
Return a list of 5 posts, each with a title and URL.
""",
expected_output="A list of 5 technical hackernews posts with titles and URLs",
agent=hacnews_agent,
tools=tools
)
crew = Crew(
agents=[hacnews_agent],
tasks=[hacnews_task],
process=Process.sequential,
verbose=True
)
result = crew.kickoff()
# Return the result in the format expected by the Chatbot component
return [(message, result.raw)]
chat_interface = gr.ChatInterface(
fn=find_hackernews_posts,
title="HackerNews Post Finder",
description="Enter a Twitter username to find relevant technical HackerNews posts.",
retry_btn=None,
undo_btn=None,
clear_btn="Clear"
)
if __name__ == "__main__":
chat_interface.launch()