Spaces:
Runtime error
Runtime error
Upload 6 files
Browse files
Dockerfile
CHANGED
|
@@ -21,8 +21,12 @@ EXPOSE 7860
|
|
| 21 |
|
| 22 |
# Set environment variables
|
| 23 |
ENV CREWAI_TELEMETRY_ENABLED=false
|
|
|
|
| 24 |
ENV GRADIO_SERVER_NAME=0.0.0.0
|
| 25 |
ENV GRADIO_SERVER_PORT=7860
|
| 26 |
|
|
|
|
|
|
|
|
|
|
| 27 |
# Command to run the Gradio app
|
| 28 |
CMD ["python", "app.py"]
|
|
|
|
| 21 |
|
| 22 |
# Set environment variables
|
| 23 |
ENV CREWAI_TELEMETRY_ENABLED=false
|
| 24 |
+
ENV CREWAI_STORAGE_DIR=/tmp/crewai
|
| 25 |
ENV GRADIO_SERVER_NAME=0.0.0.0
|
| 26 |
ENV GRADIO_SERVER_PORT=7860
|
| 27 |
|
| 28 |
+
# Create necessary directories
|
| 29 |
+
RUN mkdir -p /tmp/crewai
|
| 30 |
+
|
| 31 |
# Command to run the Gradio app
|
| 32 |
CMD ["python", "app.py"]
|
agents.py
CHANGED
|
@@ -1,4 +1,9 @@
|
|
| 1 |
# agents.py
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 2 |
|
| 3 |
from utils import gemini_llm
|
| 4 |
from crewai import Agent
|
|
|
|
| 1 |
# agents.py
|
| 2 |
+
import os
|
| 3 |
+
|
| 4 |
+
# Set CrewAI storage directory to something writable BEFORE any imports
|
| 5 |
+
os.environ["CREWAI_STORAGE_DIR"] = "/tmp/crewai"
|
| 6 |
+
os.environ["CREWAI_TELEMETRY_ENABLED"] = "false"
|
| 7 |
|
| 8 |
from utils import gemini_llm
|
| 9 |
from crewai import Agent
|
app.py
CHANGED
|
@@ -1,14 +1,19 @@
|
|
| 1 |
# interface.py
|
| 2 |
import os
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 3 |
import gradio as gr
|
| 4 |
from crewai import Crew, Process
|
| 5 |
from agents import finance_knowledge_agent, market_news_agent, stock_analysis_agent, response_refiner_agent
|
| 6 |
from tasks import get_finance_knowledge_task, get_market_news_task, get_stock_analysis_task, get_response_refiner_task
|
| 7 |
from utils import determine_question_type, search_qdrant
|
| 8 |
|
| 9 |
-
# Set CrewAI storage directory to something writable
|
| 10 |
-
os.environ["CREWAI_STORAGE_DIR"] = "/tmp/crewai"
|
| 11 |
-
|
| 12 |
# Initialize Crew
|
| 13 |
finance_crew = Crew(
|
| 14 |
agents=[finance_knowledge_agent, market_news_agent, stock_analysis_agent, response_refiner_agent],
|
|
|
|
| 1 |
# interface.py
|
| 2 |
import os
|
| 3 |
+
|
| 4 |
+
# Set CrewAI storage directory to something writable BEFORE any imports
|
| 5 |
+
os.environ["CREWAI_STORAGE_DIR"] = "/tmp/crewai"
|
| 6 |
+
os.environ["CREWAI_TELEMETRY_ENABLED"] = "false"
|
| 7 |
+
|
| 8 |
+
# Create the directory if it doesn't exist
|
| 9 |
+
os.makedirs("/tmp/crewai", exist_ok=True)
|
| 10 |
+
|
| 11 |
import gradio as gr
|
| 12 |
from crewai import Crew, Process
|
| 13 |
from agents import finance_knowledge_agent, market_news_agent, stock_analysis_agent, response_refiner_agent
|
| 14 |
from tasks import get_finance_knowledge_task, get_market_news_task, get_stock_analysis_task, get_response_refiner_task
|
| 15 |
from utils import determine_question_type, search_qdrant
|
| 16 |
|
|
|
|
|
|
|
|
|
|
| 17 |
# Initialize Crew
|
| 18 |
finance_crew = Crew(
|
| 19 |
agents=[finance_knowledge_agent, market_news_agent, stock_analysis_agent, response_refiner_agent],
|
main.py
ADDED
|
@@ -0,0 +1,63 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# main.py
|
| 2 |
+
import os
|
| 3 |
+
|
| 4 |
+
# Set CrewAI storage directory to something writable BEFORE any imports
|
| 5 |
+
os.environ["CREWAI_STORAGE_DIR"] = "/tmp/crewai"
|
| 6 |
+
os.environ["CREWAI_TELEMETRY_ENABLED"] = "false"
|
| 7 |
+
|
| 8 |
+
from crewai import Crew, Process
|
| 9 |
+
from agents import finance_knowledge_agent, market_news_agent, stock_analysis_agent, response_refiner_agent
|
| 10 |
+
from tasks import get_finance_knowledge_task, get_market_news_task, get_stock_analysis_task, get_response_refiner_task
|
| 11 |
+
from utils import determine_question_type, search_qdrant
|
| 12 |
+
|
| 13 |
+
def main():
|
| 14 |
+
"""Main function to run the finance chatbot in terminal."""
|
| 15 |
+
finance_crew = Crew(
|
| 16 |
+
agents=[finance_knowledge_agent, market_news_agent, stock_analysis_agent, response_refiner_agent],
|
| 17 |
+
tasks=[],
|
| 18 |
+
process=Process.sequential,
|
| 19 |
+
verbose=True
|
| 20 |
+
)
|
| 21 |
+
|
| 22 |
+
print("📈 Welcome to the Finance Chatbot!")
|
| 23 |
+
print("Examples: 'What is investing?', 'Analyze AAPL', 'What’s the latest market news?'")
|
| 24 |
+
while True:
|
| 25 |
+
query = input("Enter your query (type 'exit' to quit): ").strip()
|
| 26 |
+
if query.lower() == "exit":
|
| 27 |
+
print("Goodbye!")
|
| 28 |
+
break
|
| 29 |
+
|
| 30 |
+
try:
|
| 31 |
+
question_type, processed_query = determine_question_type(query)
|
| 32 |
+
finance_crew.tasks = [] # Reset tasks for each query
|
| 33 |
+
|
| 34 |
+
rag_note = "RAG_SUFFICIENT" # Default value
|
| 35 |
+
if question_type == "finance_knowledge":
|
| 36 |
+
contexts = search_qdrant(query, top_k=3)
|
| 37 |
+
context_text = "\n\n".join([f"Source: {ctx['source']}\nContent: {ctx['text']}" for ctx in contexts])
|
| 38 |
+
is_context_useful = len(context_text) > 50 and any(query.lower() in ctx["text"].lower() for ctx in contexts)
|
| 39 |
+
rag_note = "RAG_NOT_USED" if not is_context_useful else "RAG_SUFFICIENT"
|
| 40 |
+
initial_task = get_finance_knowledge_task(query)
|
| 41 |
+
elif question_type == "market_news":
|
| 42 |
+
rag_note = "NO_RAG_NEEDED" # Market news doesn't use RAG
|
| 43 |
+
initial_task = get_market_news_task(query)
|
| 44 |
+
elif question_type == "stock_analysis":
|
| 45 |
+
rag_note = "NO_RAG_NEEDED" # Stock analysis doesn't use RAG
|
| 46 |
+
initial_task = get_stock_analysis_task(processed_query)
|
| 47 |
+
else:
|
| 48 |
+
initial_task = get_finance_knowledge_task(query) # Default
|
| 49 |
+
|
| 50 |
+
finance_crew.tasks.append(initial_task)
|
| 51 |
+
initial_response = finance_crew.kickoff()
|
| 52 |
+
|
| 53 |
+
refiner_task = get_response_refiner_task(query, initial_response, question_type, rag_note=rag_note)
|
| 54 |
+
finance_crew.tasks = [refiner_task]
|
| 55 |
+
final_report = finance_crew.kickoff()
|
| 56 |
+
|
| 57 |
+
print(f"\nFinal Report:\n{final_report}\n")
|
| 58 |
+
except Exception as e:
|
| 59 |
+
print(f"Error processing query: {e}")
|
| 60 |
+
print("Please try again with a different query.\n")
|
| 61 |
+
|
| 62 |
+
if __name__ == "__main__":
|
| 63 |
+
main()
|
tasks.py
CHANGED
|
@@ -1,4 +1,9 @@
|
|
| 1 |
# tasks.py
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 2 |
|
| 3 |
from utils import search_qdrant, search_news, get_stock_data
|
| 4 |
from crewai import Task
|
|
|
|
| 1 |
# tasks.py
|
| 2 |
+
import os
|
| 3 |
+
|
| 4 |
+
# Set CrewAI storage directory to something writable BEFORE any imports
|
| 5 |
+
os.environ["CREWAI_STORAGE_DIR"] = "/tmp/crewai"
|
| 6 |
+
os.environ["CREWAI_TELEMETRY_ENABLED"] = "false"
|
| 7 |
|
| 8 |
from utils import search_qdrant, search_news, get_stock_data
|
| 9 |
from crewai import Task
|
utils.py
CHANGED
|
@@ -1,6 +1,11 @@
|
|
| 1 |
# utils.py
|
| 2 |
|
| 3 |
import os
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 4 |
from dotenv import load_dotenv
|
| 5 |
from langchain_qdrant import QdrantVectorStore
|
| 6 |
from langchain_community.embeddings import HuggingFaceEmbeddings
|
|
|
|
| 1 |
# utils.py
|
| 2 |
|
| 3 |
import os
|
| 4 |
+
|
| 5 |
+
# Set CrewAI storage directory to something writable BEFORE any imports
|
| 6 |
+
os.environ["CREWAI_STORAGE_DIR"] = "/tmp/crewai"
|
| 7 |
+
os.environ["CREWAI_TELEMETRY_ENABLED"] = "false"
|
| 8 |
+
|
| 9 |
from dotenv import load_dotenv
|
| 10 |
from langchain_qdrant import QdrantVectorStore
|
| 11 |
from langchain_community.embeddings import HuggingFaceEmbeddings
|