Spaces:
Runtime error
Runtime error
Upload 14 files
Browse files
README.md
CHANGED
|
@@ -124,18 +124,23 @@ Evaluation writes `answers_cache.json`, skips successful tasks on rerun, and sub
|
|
| 124 |
|
| 125 |
## βοΈ **Installation & Setup**
|
| 126 |
|
| 127 |
-
###
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 128 |
```bash
|
| 129 |
git clone https://github.com/fisherman611/gaia-agent.git gaia-lite
|
| 130 |
cd gaia-lite
|
| 131 |
-
```
|
| 132 |
-
|
| 133 |
-
### **2. Install Dependencies**
|
| 134 |
-
```bash
|
| 135 |
pip install -r requirements.txt
|
| 136 |
```
|
| 137 |
|
| 138 |
-
### **3. Environment Variables**
|
| 139 |
Create a `.env` file with your API keys:
|
| 140 |
```env
|
| 141 |
SUPABASE_URL=your_supabase_url
|
|
|
|
| 124 |
|
| 125 |
## βοΈ **Installation & Setup**
|
| 126 |
|
| 127 |
+
### Hugging Face Space secrets (most common crash)
|
| 128 |
+
|
| 129 |
+
If logs say `GROQ_API_KEY` is missing, open the Space β **Settings β Variables and secrets** and add at least:
|
| 130 |
+
|
| 131 |
+
- `GROQ_API_KEY` β from https://console.groq.com/keys
|
| 132 |
+
- `TAVILY_API_KEY` β for web search
|
| 133 |
+
|
| 134 |
+
Then **Restart** the Space. Do not put keys in public git.
|
| 135 |
+
|
| 136 |
+
### Local setup
|
| 137 |
+
|
| 138 |
```bash
|
| 139 |
git clone https://github.com/fisherman611/gaia-agent.git gaia-lite
|
| 140 |
cd gaia-lite
|
|
|
|
|
|
|
|
|
|
|
|
|
| 141 |
pip install -r requirements.txt
|
| 142 |
```
|
| 143 |
|
|
|
|
| 144 |
Create a `.env` file with your API keys:
|
| 145 |
```env
|
| 146 |
SUPABASE_URL=your_supabase_url
|
agent.py
CHANGED
|
@@ -217,12 +217,24 @@ def _should_force_final(messages) -> bool:
|
|
| 217 |
return False
|
| 218 |
|
| 219 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 220 |
def build_graph(provider: str = "groq", use_retriever: bool = False):
|
| 221 |
"""Compile the tool-calling graph. Retriever is off unless explicitly enabled."""
|
| 222 |
if provider != "groq":
|
| 223 |
raise ValueError("Only provider='groq' is supported after the refactor.")
|
| 224 |
|
| 225 |
-
|
|
|
|
| 226 |
llm_with_tools = llm.bind_tools(TOOLS)
|
| 227 |
|
| 228 |
retriever_store = _build_optional_retriever() if use_retriever else None
|
|
|
|
| 217 |
return False
|
| 218 |
|
| 219 |
|
| 220 |
+
def require_env(name: str) -> str:
|
| 221 |
+
value = os.getenv(name, "").strip()
|
| 222 |
+
if value:
|
| 223 |
+
return value
|
| 224 |
+
raise RuntimeError(
|
| 225 |
+
f"Missing {name}. "
|
| 226 |
+
"Local: put it in `.env`. "
|
| 227 |
+
"Hugging Face Space: Settings β Variables and secrets β New secret."
|
| 228 |
+
)
|
| 229 |
+
|
| 230 |
+
|
| 231 |
def build_graph(provider: str = "groq", use_retriever: bool = False):
|
| 232 |
"""Compile the tool-calling graph. Retriever is off unless explicitly enabled."""
|
| 233 |
if provider != "groq":
|
| 234 |
raise ValueError("Only provider='groq' is supported after the refactor.")
|
| 235 |
|
| 236 |
+
api_key = require_env("GROQ_API_KEY")
|
| 237 |
+
llm = ChatGroq(model="qwen/qwen3-32b", temperature=0, api_key=api_key)
|
| 238 |
llm_with_tools = llm.bind_tools(TOOLS)
|
| 239 |
|
| 240 |
retriever_store = _build_optional_retriever() if use_retriever else None
|
app.py
CHANGED
|
@@ -3,15 +3,42 @@ import os
|
|
| 3 |
from typing import List, Tuple, Optional
|
| 4 |
from agent import build_graph, run_agent
|
| 5 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 6 |
class QnAChatbot:
|
| 7 |
"""A Q&A chatbot interface for the agent."""
|
| 8 |
|
| 9 |
def __init__(self):
|
| 10 |
print("π€ QnAChatbot initializing...")
|
| 11 |
-
|
| 12 |
-
self.graph = build_graph()
|
| 13 |
self.conversation_history = []
|
| 14 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 15 |
|
| 16 |
def process_question(self, question: str, history: List[Tuple[str, str]], uploaded_files: Optional[List] = None) -> Tuple[str, List[Tuple[str, str]]]:
|
| 17 |
"""Process a question and return the response with updated history."""
|
|
@@ -24,6 +51,8 @@ class QnAChatbot:
|
|
| 24 |
print(f"π€ Processing new question...")
|
| 25 |
print(f"π Question: {question[:100]}{'...' if len(question) > 100 else ''}")
|
| 26 |
print(f"π Files uploaded: {len(uploaded_files) if uploaded_files else 0}")
|
|
|
|
|
|
|
| 27 |
|
| 28 |
file_paths = []
|
| 29 |
if uploaded_files:
|
|
@@ -627,6 +656,14 @@ def create_qna_interface():
|
|
| 627 |
"""
|
| 628 |
|
| 629 |
with gr.Blocks(css=custom_css, title="GAIA Lite", theme=gr.themes.Soft()) as demo:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 630 |
# Header with enhanced styling
|
| 631 |
with gr.Row(elem_classes="main-content"):
|
| 632 |
gr.Markdown(
|
|
|
|
| 3 |
from typing import List, Tuple, Optional
|
| 4 |
from agent import build_graph, run_agent
|
| 5 |
|
| 6 |
+
REQUIRED_SECRETS = ("GROQ_API_KEY", "TAVILY_API_KEY")
|
| 7 |
+
|
| 8 |
+
|
| 9 |
+
def missing_secrets() -> List[str]:
|
| 10 |
+
return [name for name in REQUIRED_SECRETS if not os.getenv(name, "").strip()]
|
| 11 |
+
|
| 12 |
+
|
| 13 |
class QnAChatbot:
|
| 14 |
"""A Q&A chatbot interface for the agent."""
|
| 15 |
|
| 16 |
def __init__(self):
|
| 17 |
print("π€ QnAChatbot initializing...")
|
| 18 |
+
self.graph = None
|
|
|
|
| 19 |
self.conversation_history = []
|
| 20 |
+
missing = missing_secrets()
|
| 21 |
+
if missing:
|
| 22 |
+
print(f"β οΈ Space can start, but these secrets are missing: {', '.join(missing)}")
|
| 23 |
+
print(" Hugging Face Space: Settings β Variables and secrets")
|
| 24 |
+
else:
|
| 25 |
+
print("π§ Building agent graph...")
|
| 26 |
+
self.graph = build_graph()
|
| 27 |
+
print("β
QnAChatbot initialized successfully")
|
| 28 |
+
|
| 29 |
+
def _ensure_graph(self):
|
| 30 |
+
if self.graph is not None:
|
| 31 |
+
return
|
| 32 |
+
missing = missing_secrets()
|
| 33 |
+
if missing:
|
| 34 |
+
raise RuntimeError(
|
| 35 |
+
"Missing API secrets: "
|
| 36 |
+
+ ", ".join(missing)
|
| 37 |
+
+ ". Add them in Hugging Face Space Settings β Variables and secrets, "
|
| 38 |
+
"then restart the Space. Locally, put them in `.env`."
|
| 39 |
+
)
|
| 40 |
+
print("π§ Building agent graph on first use...")
|
| 41 |
+
self.graph = build_graph()
|
| 42 |
|
| 43 |
def process_question(self, question: str, history: List[Tuple[str, str]], uploaded_files: Optional[List] = None) -> Tuple[str, List[Tuple[str, str]]]:
|
| 44 |
"""Process a question and return the response with updated history."""
|
|
|
|
| 51 |
print(f"π€ Processing new question...")
|
| 52 |
print(f"π Question: {question[:100]}{'...' if len(question) > 100 else ''}")
|
| 53 |
print(f"π Files uploaded: {len(uploaded_files) if uploaded_files else 0}")
|
| 54 |
+
|
| 55 |
+
self._ensure_graph()
|
| 56 |
|
| 57 |
file_paths = []
|
| 58 |
if uploaded_files:
|
|
|
|
| 656 |
"""
|
| 657 |
|
| 658 |
with gr.Blocks(css=custom_css, title="GAIA Lite", theme=gr.themes.Soft()) as demo:
|
| 659 |
+
missing = missing_secrets()
|
| 660 |
+
if missing:
|
| 661 |
+
gr.Markdown(
|
| 662 |
+
"β οΈ **Missing secrets:** `"
|
| 663 |
+
+ "`, `".join(missing)
|
| 664 |
+
+ "`. Add them in **Space Settings β Variables and secrets**, then restart. "
|
| 665 |
+
"Until then the UI loads but questions will fail."
|
| 666 |
+
)
|
| 667 |
# Header with enhanced styling
|
| 668 |
with gr.Row(elem_classes="main-content"):
|
| 669 |
gr.Markdown(
|