HANTAEK commited on
Commit
ad5d82d
·
verified ·
1 Parent(s): c7e69ff

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +85 -86
app.py CHANGED
@@ -1,86 +1,85 @@
1
- # 환경 변수에서 API 키 가져오기
2
- import os
3
- from dotenv import load_dotenv
4
-
5
- # CrewAI 라이브러리에서 필요한 클래스 가져오기
6
- from crewai import Agent, Task, Crew, Process
7
- from langchain_openai import ChatOpenAI
8
- import gradio as gr
9
-
10
- load_dotenv()
11
-
12
- # LLM
13
- llm = ChatOpenAI(model='gpt-4o-mini', temperature=0.3)
14
-
15
- # Search Tool
16
- from langchain_community.tools.tavily_search import TavilySearchResults
17
-
18
- search_tool = TavilySearchResults()
19
-
20
- def run_crypto_crew(topic):
21
-
22
- # Agent
23
- researcher = Agent(
24
- role='Market Researcher',
25
- goal=f'Uncover emerging trends and investment opportunities in the cryptocurrency market in 2025. Focus on the topic: {topic}.',
26
- backstory='Identify groundbreaking trends and actionable insights.',
27
- verbose=True,
28
- tools=[search_tool],
29
- allow_delegation=False,
30
- llm=llm,
31
- max_iter=3,
32
- max_rpm=10,
33
- )
34
-
35
-
36
- analyst = Agent(
37
- role='Investment Analyst',
38
- goal=f'Analyze cryptocurrency market data to extract actionable insights and investment leads. Focus on the topic: {topic}.',
39
- backstory='Draw meaningful conclusions from cryptocurrency market data.',
40
- verbose=True,
41
- allow_delegation=False,
42
- llm=llm,
43
- )
44
-
45
-
46
- # Tasks
47
- research_task = Task(
48
- description=f'Explore the internet to pinpoint emerging trends and potential investment opportunities. Focus on the topic: {topic}.',
49
- agent=researcher,
50
- expected_output='A detailed summary of the reserch results in string format'
51
- )
52
-
53
-
54
- analyst_task = Task(
55
- description=f'Analyze the provided cryptocurrency market data to extract key insights and compile a concise report in Korean language. Focus on the topic: {topic}.',
56
- agent=analyst,
57
- expected_output='A refined finalized version of the report in string format'
58
- )
59
-
60
-
61
- #`Crew` is a group of agents working together to accomplish a task
62
- crypto_crew = Crew(
63
- agents=[researcher, analyst],
64
- tasks=[research_task, analyst_task],
65
- process=Process.sequential
66
- )
67
-
68
- #`kickoff` method starts the crew's process
69
- result = crypto_crew.kickoff()
70
-
71
- return result.raw # raw text 속성을 출력
72
-
73
-
74
- def process_query(message, history):
75
- return run_crypto_crew(message)
76
-
77
-
78
- if __name__ == '__main__':
79
- app = gr.ChatInterface(
80
- fn=process_query,
81
- type="messages",
82
- title="Crypto Investment Advisor Bot",
83
- description="암호화폐 관련 트렌드를 파악하여 투자 인사이트를 제공해 드립니다."
84
- )
85
-
86
- app.launch()
 
1
+ # 환경 변수에서 API 키 가져오기
2
+ from dotenv import load_dotenv
3
+
4
+ # CrewAI 라이브러리에서 필요한 클래스 가져오기
5
+ from crewai import Agent, Task, Crew, Process
6
+ from langchain_openai import ChatOpenAI
7
+ import gradio as gr
8
+
9
+ load_dotenv()
10
+
11
+ # LLM
12
+ llm = ChatOpenAI(model='gpt-4o-mini', temperature=0.3)
13
+
14
+ # Search Tool
15
+ from langchain_community.tools.tavily_search import TavilySearchResults
16
+
17
+ search_tool = TavilySearchResults()
18
+
19
+ def run_crypto_crew(topic):
20
+
21
+ # Agent
22
+ researcher = Agent(
23
+ role='Market Researcher',
24
+ goal=f'Uncover emerging trends and investment opportunities in the cryptocurrency market in 2025. Focus on the topic: {topic}.',
25
+ backstory='Identify groundbreaking trends and actionable insights.',
26
+ verbose=True,
27
+ tools=[search_tool],
28
+ allow_delegation=False,
29
+ llm=llm,
30
+ max_iter=3,
31
+ max_rpm=10,
32
+ )
33
+
34
+
35
+ analyst = Agent(
36
+ role='Investment Analyst',
37
+ goal=f'Analyze cryptocurrency market data to extract actionable insights and investment leads. Focus on the topic: {topic}.',
38
+ backstory='Draw meaningful conclusions from cryptocurrency market data.',
39
+ verbose=True,
40
+ allow_delegation=False,
41
+ llm=llm,
42
+ )
43
+
44
+
45
+ # Tasks
46
+ research_task = Task(
47
+ description=f'Explore the internet to pinpoint emerging trends and potential investment opportunities. Focus on the topic: {topic}.',
48
+ agent=researcher,
49
+ expected_output='A detailed summary of the reserch results in string format'
50
+ )
51
+
52
+
53
+ analyst_task = Task(
54
+ description=f'Analyze the provided cryptocurrency market data to extract key insights and compile a concise report in Korean language. Focus on the topic: {topic}.',
55
+ agent=analyst,
56
+ expected_output='A refined finalized version of the report in string format'
57
+ )
58
+
59
+
60
+ #`Crew` is a group of agents working together to accomplish a task
61
+ crypto_crew = Crew(
62
+ agents=[researcher, analyst],
63
+ tasks=[research_task, analyst_task],
64
+ process=Process.sequential
65
+ )
66
+
67
+ #`kickoff` method starts the crew's process
68
+ result = crypto_crew.kickoff()
69
+
70
+ return result.raw # raw text 속성을 출력
71
+
72
+
73
+ def process_query(message, history):
74
+ return run_crypto_crew(message)
75
+
76
+
77
+ if __name__ == '__main__':
78
+ app = gr.ChatInterface(
79
+ fn=process_query,
80
+ type="messages",
81
+ title="Crypto Investment Advisor Bot",
82
+ description="암호화폐 관련 트렌드를 파악하여 투자 인사이트를 제공해 드립니다."
83
+ )
84
+
85
+ app.launch()