shekkari21 commited on
Commit
8d5b1f0
·
1 Parent(s): 5b81afa

made changes

Browse files
Files changed (4) hide show
  1. README.md +43 -1
  2. app.py +2 -3
  3. config.py +63 -14
  4. main.py +2 -1
README.md CHANGED
@@ -9,4 +9,46 @@ app_file: app.py
9
  pinned: false
10
  ---
11
 
12
- Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
9
  pinned: false
10
  ---
11
 
12
+ # NBA Data Analysis with CrewAI
13
+
14
+ An intelligent NBA data analysis application powered by CrewAI agents. Upload your NBA CSV data and get comprehensive analysis with insights, statistics, and engaging storylines.
15
+
16
+ ## Features
17
+
18
+ - 📊 **Data Engineering**: Automatic data cleaning and preparation
19
+ - 🔍 **Intelligent Analysis**: AI-powered insights and pattern detection
20
+ - 📈 **Statistical Analysis**: Top performers, trends, and key metrics
21
+ - 📝 **Storytelling**: Engaging headlines and narratives from data
22
+ - 🎯 **Semantic Search**: Natural language queries on your data
23
+
24
+ ## How to Use
25
+
26
+ 1. **Upload a CSV file** with NBA data
27
+ 2. **Enter your analysis query** (or leave blank for comprehensive analysis)
28
+ 3. **Click "Analyze Dataset"** and wait for results
29
+ 4. **View insights** from Engineer, Analyst, and Storyteller agents
30
+
31
+ ## Example Queries
32
+
33
+ - "Who are the top 5 three-point shooters?"
34
+ - "Show me the best scoring games this season"
35
+ - "Which players have the highest field goal percentage?"
36
+ - "Analyze team performance trends"
37
+
38
+ ## Technology Stack
39
+
40
+ - **CrewAI**: Multi-agent AI framework
41
+ - **Gradio**: Web interface
42
+ - **Pandas**: Data analysis
43
+ - **ChromaDB**: Vector database for semantic search
44
+ - **OpenRouter**: Free open-source LLM access
45
+
46
+ ## Free to Use
47
+
48
+ This application uses free-tier services:
49
+ - OpenRouter for LLM access (free tier)
50
+ - Hugging Face Spaces for hosting (free tier)
51
+
52
+ ---
53
+
54
+ Built with ❤️ using CrewAI
app.py CHANGED
@@ -326,10 +326,9 @@ if __name__ == "__main__":
326
  print("Creating Gradio app...")
327
  app = create_app()
328
  print("Launching Gradio app...")
 
 
329
  app.launch(
330
- server_name="0.0.0.0",
331
- server_port=7860,
332
- share=False,
333
  show_error=True
334
  )
335
  except Exception as e:
 
326
  print("Creating Gradio app...")
327
  app = create_app()
328
  print("Launching Gradio app...")
329
+ # For Hugging Face Spaces, use default launch settings
330
+ # Spaces will automatically handle server_name and port
331
  app.launch(
 
 
 
332
  show_error=True
333
  )
334
  except Exception as e:
config.py CHANGED
@@ -7,31 +7,80 @@ from crewai import LLM
7
  # NBA Data Configuration
8
  NBA_DATA_PATH = "nba24-25.csv"
9
 
 
 
 
 
 
10
  # OpenAI Configuration
11
  OPENAI_API_KEY = os.getenv("OPENAI_API_KEY")
12
- OPENAI_MODEL = os.getenv("OPENAI_MODEL", "gpt-4o")
 
 
 
 
 
 
 
 
13
 
14
- # Validate OpenAI API key (only raise error when actually trying to use LLM, not on import)
15
- # This allows the app to load even if API key isn't set yet
 
16
 
17
 
18
  def get_llm() -> LLM:
19
  """
20
- Create and return a CrewAI LLM instance configured for OpenAI.
21
 
22
  Returns:
23
- LLM: Configured CrewAI LLM instance for OpenAI
24
 
25
  Raises:
26
- ValueError: If OPENAI_API_KEY is not set
27
  """
28
- if not OPENAI_API_KEY:
29
- raise ValueError(
30
- "OPENAI_API_KEY environment variable is not set. "
31
- "Please set it using: export OPENAI_API_KEY='your-api-key'"
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
32
  )
33
- return LLM(
34
- model=OPENAI_MODEL,
35
- api_key=OPENAI_API_KEY
36
- )
37
 
 
7
  # NBA Data Configuration
8
  NBA_DATA_PATH = "nba24-25.csv"
9
 
10
+ # LLM Configuration - Choose your provider
11
+ # Options: "openai", "ollama", "litellm", "openrouter"
12
+ # Default to openrouter for free tier access
13
+ LLM_PROVIDER = os.getenv("LLM_PROVIDER", "openrouter") # Default to free tier
14
+
15
  # OpenAI Configuration
16
  OPENAI_API_KEY = os.getenv("OPENAI_API_KEY")
17
+ OPENAI_MODEL = os.getenv("OPENAI_MODEL", "gpt-4o")
18
+
19
+ # Ollama Configuration (for local open-source models)
20
+ OLLAMA_BASE_URL = os.getenv("OLLAMA_BASE_URL", "http://localhost:11434")
21
+ OLLAMA_MODEL = os.getenv("OLLAMA_MODEL", "llama3.2") # Options: llama3.2, mistral, qwen2.5, etc.
22
+
23
+ # LiteLLM Configuration (for Hugging Face or other providers)
24
+ LITELLM_MODEL = os.getenv("LITELLM_MODEL", "huggingface/meta-llama/Llama-3.2-3B-Instruct")
25
+ LITELLM_API_KEY = os.getenv("LITELLM_API_KEY", "") # Optional, depends on provider
26
 
27
+ # OpenRouter Configuration (access to many open-source models)
28
+ OPENROUTER_API_KEY = os.getenv("OPENROUTER_API_KEY")
29
+ OPENROUTER_MODEL = os.getenv("OPENROUTER_MODEL", "meta-llama/llama-3.2-3b-instruct:free") # Free tier available
30
 
31
 
32
  def get_llm() -> LLM:
33
  """
34
+ Create and return a CrewAI LLM instance based on the configured provider.
35
 
36
  Returns:
37
+ LLM: Configured CrewAI LLM instance
38
 
39
  Raises:
40
+ ValueError: If required configuration is not set
41
  """
42
+ if LLM_PROVIDER == "ollama":
43
+ # Option 1: Ollama (local open-source models)
44
+ # Install: brew install ollama (Mac) or see https://ollama.ai
45
+ # Run: ollama pull llama3.2
46
+ return LLM(
47
+ model=OLLAMA_MODEL,
48
+ base_url=OLLAMA_BASE_URL,
49
+ api_key="ollama" # Ollama doesn't require a real API key, but CrewAI needs something
50
+ )
51
+
52
+ elif LLM_PROVIDER == "litellm":
53
+ # Option 2: LiteLLM (supports Hugging Face, Together AI, etc.)
54
+ # Format: huggingface/model-name or together_ai/model-name
55
+ return LLM(
56
+ model=f"litellm/{LITELLM_MODEL}",
57
+ api_key=LITELLM_API_KEY if LITELLM_API_KEY else "dummy" # Some providers don't need keys
58
+ )
59
+
60
+ elif LLM_PROVIDER == "openrouter":
61
+ # Option 3: OpenRouter (access to many open-source models)
62
+ # Free tier available: https://openrouter.ai
63
+ # Note: For Hugging Face Spaces, set OPENROUTER_API_KEY as a secret
64
+ if not OPENROUTER_API_KEY:
65
+ # Try to use without key (some free models might work)
66
+ # But it's better to set the key for reliability
67
+ print("Warning: OPENROUTER_API_KEY not set. Some models may not work.")
68
+ print("Get a free key at https://openrouter.ai")
69
+ return LLM(
70
+ model=OPENROUTER_MODEL,
71
+ base_url="https://openrouter.ai/api/v1",
72
+ api_key=OPENROUTER_API_KEY if OPENROUTER_API_KEY else "free"
73
+ )
74
+
75
+ else:
76
+ # Default: OpenAI (original configuration)
77
+ if not OPENAI_API_KEY:
78
+ raise ValueError(
79
+ "OPENAI_API_KEY environment variable is not set. "
80
+ "Please set it using: export OPENAI_API_KEY='your-api-key'"
81
+ )
82
+ return LLM(
83
+ model=OPENAI_MODEL,
84
+ api_key=OPENAI_API_KEY
85
  )
 
 
 
 
86
 
main.py CHANGED
@@ -11,7 +11,8 @@ def main():
11
  """Main function to run the NBA data analysis crew."""
12
  print("=" * 60)
13
  print("NBA 2024-25 Data Analysis with CrewAI")
14
- print("Using OpenAI")
 
15
  print("=" * 60)
16
  print()
17
 
 
11
  """Main function to run the NBA data analysis crew."""
12
  print("=" * 60)
13
  print("NBA 2024-25 Data Analysis with CrewAI")
14
+ from config import LLM_PROVIDER
15
+ print(f"Using LLM Provider: {LLM_PROVIDER.upper()}")
16
  print("=" * 60)
17
  print()
18