Spaces:
Sleeping
Sleeping
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-4") | |
toolset = ComposioToolSet() | |
tools = toolset.get_tools(apps=[App.SERPAPI, App.WEBTOOL]) | |
def find_hackernews_posts(message): | |
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. | |
""", | |
expected_output="A list of technical hackernews posts printed", | |
agent=hacnews_agent, | |
tools=tools | |
) | |
crew = Crew( | |
agents=[hacnews_agent], | |
tasks=[hacnews_task], | |
process=Process.sequential, | |
verbose=True | |
) | |
result = crew.kickoff() | |
return result | |
chat_interface = gr.ChatInterface( | |
fn=find_hackernews_posts, | |
title="HackerNews Post Finder", | |
description="Enter a Twitter username to find relevant technical HackerNews posts.", | |
examples=[ | |
["elonmusk"], | |
["naval"], | |
["paulg"] | |
], | |
retry_btn=None, | |
undo_btn=None, | |
clear_btn="Clear" | |
) | |
if __name__ == "__main__": | |
chat_interface.launch() |