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

Upload app.py

Browse files
Files changed (1) hide show
  1. app.py +86 -0
app.py ADDED
@@ -0,0 +1,86 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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()