Spaces:
Build error
Build error
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,63 +1,61 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
-
from
|
| 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 |
-
value=0.95,
|
| 55 |
-
step=0.05,
|
| 56 |
-
label="Top-p (nucleus sampling)",
|
| 57 |
-
),
|
| 58 |
],
|
|
|
|
|
|
|
|
|
|
| 59 |
)
|
| 60 |
|
| 61 |
-
|
| 62 |
if __name__ == "__main__":
|
| 63 |
-
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
+
from composio_crewai import ComposioToolSet, App, Action
|
| 3 |
+
from crewai import Agent, Task, Crew, Process
|
| 4 |
+
from langchain_openai import ChatOpenAI
|
| 5 |
+
from dotenv import load_dotenv
|
| 6 |
+
import os
|
| 7 |
+
|
| 8 |
+
load_dotenv()
|
| 9 |
+
|
| 10 |
+
llm = ChatOpenAI(model="gpt-4")
|
| 11 |
+
|
| 12 |
+
toolset = ComposioToolSet()
|
| 13 |
+
tools = toolset.get_tools(apps=[App.SERPAPI, App.WEBTOOL])
|
| 14 |
+
|
| 15 |
+
def find_hackernews_posts(message):
|
| 16 |
+
profile = message
|
| 17 |
+
|
| 18 |
+
hacnews_agent = Agent(
|
| 19 |
+
role="Technical Researcher",
|
| 20 |
+
goal="Find the best technical posts on Hackernews",
|
| 21 |
+
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.",
|
| 22 |
+
llm=llm,
|
| 23 |
+
tools=tools
|
| 24 |
+
)
|
| 25 |
+
|
| 26 |
+
hacnews_task = Task(
|
| 27 |
+
description=f"""
|
| 28 |
+
Use the serp tool to search for the user's twitter profile of name {profile} to read his bio,
|
| 29 |
+
and then scrape it. Based on his bio, find good technical hackernews posts suited to his bio.
|
| 30 |
+
""",
|
| 31 |
+
expected_output="A list of technical hackernews posts printed",
|
| 32 |
+
agent=hacnews_agent,
|
| 33 |
+
tools=tools
|
| 34 |
+
)
|
| 35 |
+
|
| 36 |
+
crew = Crew(
|
| 37 |
+
agents=[hacnews_agent],
|
| 38 |
+
tasks=[hacnews_task],
|
| 39 |
+
process=Process.sequential,
|
| 40 |
+
verbose=True
|
| 41 |
+
)
|
| 42 |
+
|
| 43 |
+
result = crew.kickoff()
|
| 44 |
+
return result
|
| 45 |
+
|
| 46 |
+
chat_interface = gr.ChatInterface(
|
| 47 |
+
fn=find_hackernews_posts,
|
| 48 |
+
title="HackerNews Post Finder",
|
| 49 |
+
description="Enter a Twitter username to find relevant technical HackerNews posts.",
|
| 50 |
+
examples=[
|
| 51 |
+
["elonmusk"],
|
| 52 |
+
["naval"],
|
| 53 |
+
["paulg"]
|
|
|
|
|
|
|
|
|
|
|
|
|
| 54 |
],
|
| 55 |
+
retry_btn=None,
|
| 56 |
+
undo_btn=None,
|
| 57 |
+
clear_btn="Clear"
|
| 58 |
)
|
| 59 |
|
|
|
|
| 60 |
if __name__ == "__main__":
|
| 61 |
+
chat_interface.launch()
|