Download app.py from devCmin/chatbot: direct link, hf CLI and curl.
- Browser
- Download file 2.7 kB
-
https://huggingface.co/spaces/devCmin/chatbot/resolve/main/app.py
- Command line
-
hf download hf://spaces/devCmin/chatbot/app.py
-
curl -L -o app.py https://huggingface.co/spaces/devCmin/chatbot/resolve/main/app.py
2.7 kB
| # ํ๊ฒฝ ๋ณ์์์ API ํค ๊ฐ์ ธ์ค๊ธฐ | |
| import os | |
| from dotenv import load_dotenv | |
| load_dotenv() | |
| OPENAI_API_KEY = os.getenv("OPENAI_API_KEY") | |
| TAVILY_API_KEY = os.getenv("TAVILY_API_KEY") | |
| # CrewAI ๋ผ์ด๋ธ๋ฌ๋ฆฌ์์ ํ์ํ ํด๋์ค ๊ฐ์ ธ์ค๊ธฐ | |
| from crewai import Agent, Task, Crew, Process | |
| from langchain_openai import ChatOpenAI | |
| import gradio as gr | |
| # LLM | |
| llm = ChatOpenAI(model='gpt-3.5-turbo', temperature=0, | |
| api_key=OPENAI_API_KEY) | |
| # Search Tool | |
| from langchain_community.tools.tavily_search import TavilySearchResults | |
| search_tool = TavilySearchResults(api_key=TAVILY_API_KEY) | |
| def run_crypto_crew(topic): | |
| # Agent | |
| researcher = Agent( | |
| role='Market Researcher', | |
| goal=f'Uncover emerging trends and investment opportunities in the cryptocurrency market in 2024. Focus on the topic: {topic}.', | |
| backstory='Identify groundbreaking trends and actionable insights.', | |
| verbose=True, | |
| tools=[search_tool], | |
| allow_delegation=False, | |
| llm=llm, | |
| max_iter=3, | |
| max_rpm=10, | |
| ) | |
| analyst = Agent( | |
| role='Investment Analyst', | |
| goal=f'Analyze cryptocurrency market data to extract actionable insights and investment leads. Focus on the topic: {topic}.', | |
| backstory='Draw meaningful conclusions from cryptocurrency market data.', | |
| verbose=True, | |
| allow_delegation=False, | |
| llm=llm, | |
| ) | |
| # Tasks | |
| research_task = Task( | |
| description=f'Explore the internet to pinpoint emerging trends and potential investment opportunities. Focus on the topic: {topic}.', | |
| agent=researcher, | |
| expected_output='A detailed summary of the reserch results in string format' | |
| ) | |
| analyst_task = Task( | |
| description=f'Analyze the provided cryptocurrency market data to extract key insights and compile a concise report in Korean Hangul. Focus on the topic: {topic}.', | |
| agent=analyst, | |
| expected_output='A refined finalized version of the report in string format' | |
| ) | |
| #`Crew` is a group of agents working together to accomplish a task | |
| crypto_crew = Crew( | |
| agents=[researcher, analyst], | |
| tasks=[research_task, analyst_task], | |
| process=Process.sequential | |
| ) | |
| #`kickoff` method starts the crew's process | |
| result = crypto_crew.kickoff() | |
| return result | |
| def process_query(message, history): | |
| return run_crypto_crew(message) | |
| if __name__ == '__main__': | |
| app = gr.ChatInterface( | |
| fn=process_query, | |
| title="Crypto Investment Advisor Bot", | |
| description="์ํธํํ ๊ด๋ จ ํธ๋ ๋๋ฅผ ํ์ ํ์ฌ ํฌ์ ์ธ์ฌ์ดํธ๋ฅผ ์ ๊ณตํด ๋๋ฆฝ๋๋ค." | |
| ) | |
| app.launch() | |