Entz commited on
Commit
f28426a
·
verified ·
1 Parent(s): 5849d21

Upload 8 files

Browse files
Files changed (3) hide show
  1. backend.py +16 -3
  2. huggingface.yaml +1 -1
  3. requirements.txt +0 -1
backend.py CHANGED
@@ -4,19 +4,32 @@ Backend module for MCP Agent
4
  Handles all the MCP server connections, LLM setup, and agent logic
5
  """
6
  import sys
7
- from pathlib import Path
8
  import os
9
  import re
10
  import asyncio
11
  from dotenv import load_dotenv
12
  from typing import Optional, Dict, List, Any
13
 
 
 
 
 
14
  ################### --- Auth setup --- ###################
15
  ##########################################################
16
  # load the details from .env, then test it and raise as Asserterror if false
17
- load_dotenv()
18
  HF = os.getenv("HF_TOKEN") or os.getenv("HUGGINGFACEHUB_API_TOKEN")
19
- assert HF, "Set HF_TOKEN (or HUGGINGFACEHUB_API_TOKEN) in your environment/.env"
 
 
 
 
 
 
 
 
 
 
20
 
21
  # then all env set to the same token to avoid env error.
22
  os.environ["HF_TOKEN"] = HF
 
4
  Handles all the MCP server connections, LLM setup, and agent logic
5
  """
6
  import sys
 
7
  import os
8
  import re
9
  import asyncio
10
  from dotenv import load_dotenv
11
  from typing import Optional, Dict, List, Any
12
 
13
+ from pathlib import Path # already imported
14
+ here = Path(__file__).parent.resolve()
15
+
16
+
17
  ################### --- Auth setup --- ###################
18
  ##########################################################
19
  # load the details from .env, then test it and raise as Asserterror if false
20
+ # load_dotenv()
21
  HF = os.getenv("HF_TOKEN") or os.getenv("HUGGINGFACEHUB_API_TOKEN")
22
+ if not HF:
23
+ print("WARNING: HF_TOKEN not set. The app will start, but model calls may fail.")
24
+ else:
25
+ os.environ["HF_TOKEN"] = HF
26
+ os.environ["HUGGINGFACEHUB_API_TOKEN"] = HF
27
+ try:
28
+ from huggingface_hub import login
29
+ login(token=HF)
30
+ except Exception:
31
+ pass
32
+
33
 
34
  # then all env set to the same token to avoid env error.
35
  os.environ["HF_TOKEN"] = HF
huggingface.yaml CHANGED
@@ -3,4 +3,4 @@
3
  title: mcp-stock-math
4
  sdk: streamlit
5
  app_file: frontend.py
6
- python_version: "3.10"
 
3
  title: mcp-stock-math
4
  sdk: streamlit
5
  app_file: frontend.py
6
+ python_version: "3.10"
requirements.txt CHANGED
@@ -7,4 +7,3 @@ streamlit==1.48.0
7
  python-dotenv
8
  huggingface-hub
9
  fastmcp
10
-
 
7
  python-dotenv
8
  huggingface-hub
9
  fastmcp