Update app.py
Browse files
app.py
CHANGED
@@ -1,86 +1,85 @@
|
|
1 |
-
# 환경 변수에서 API 키 가져오기
|
2 |
-
import
|
3 |
-
|
4 |
-
|
5 |
-
|
6 |
-
from
|
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 |
-
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()
|
|