Spaces:
Sleeping
Sleeping
Fix: Add proper nano-graphrag dependencies and environment setup
Browse files- Add required dependencies (pandas, scikit-learn, sentence-transformers)
- Add OpenAI API key environment variable checking
- Improve diagnostic function with detailed system info
- Prepare for real GraphRAG functionality instead of demo mode
- .gitignore +1 -0
- __pycache__/app.cpython-313.pyc +0 -0
- app.py +28 -2
- requirements.txt +5 -1
.gitignore
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
.vercel
|
__pycache__/app.cpython-313.pyc
ADDED
|
Binary file (15.3 kB). View file
|
|
|
app.py
CHANGED
|
@@ -7,6 +7,17 @@ from pathlib import Path
|
|
| 7 |
from typing import Dict, Any, List
|
| 8 |
import tempfile
|
| 9 |
import shutil
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 10 |
|
| 11 |
# Try to import nano_graphrag, with fallback for demo
|
| 12 |
try:
|
|
@@ -268,15 +279,30 @@ def api_query(query: str, mode: str = "local", book_id: str = None):
|
|
| 268 |
# Diagnostic function
|
| 269 |
def diagnostic_info():
|
| 270 |
"""Return diagnostic information about the system"""
|
| 271 |
-
|
| 272 |
"nano_graphrag_available": NANO_GRAPHRAG_AVAILABLE,
|
| 273 |
"available_books": available_books,
|
| 274 |
"current_book": borges_rag.current_book,
|
| 275 |
"working_directory": os.getcwd(),
|
| 276 |
"directory_contents": [f for f in os.listdir('.') if os.path.isdir(f)],
|
| 277 |
-
"book_status": book_status
|
|
|
|
|
|
|
|
|
|
| 278 |
}
|
| 279 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 280 |
# Gradio app
|
| 281 |
with gr.Blocks(
|
| 282 |
title="Borges Graph - GraphRAG Explorer",
|
|
|
|
| 7 |
from typing import Dict, Any, List
|
| 8 |
import tempfile
|
| 9 |
import shutil
|
| 10 |
+
from dotenv import load_dotenv
|
| 11 |
+
|
| 12 |
+
# Load environment variables
|
| 13 |
+
load_dotenv()
|
| 14 |
+
|
| 15 |
+
# Check for OpenAI API key
|
| 16 |
+
if not os.getenv("OPENAI_API_KEY"):
|
| 17 |
+
print("⚠️ OPENAI_API_KEY not found in environment variables")
|
| 18 |
+
print("⚠️ nano-graphrag requires OpenAI API key to function")
|
| 19 |
+
else:
|
| 20 |
+
print("✅ OpenAI API key found in environment")
|
| 21 |
|
| 22 |
# Try to import nano_graphrag, with fallback for demo
|
| 23 |
try:
|
|
|
|
| 279 |
# Diagnostic function
|
| 280 |
def diagnostic_info():
|
| 281 |
"""Return diagnostic information about the system"""
|
| 282 |
+
diagnostic_data = {
|
| 283 |
"nano_graphrag_available": NANO_GRAPHRAG_AVAILABLE,
|
| 284 |
"available_books": available_books,
|
| 285 |
"current_book": borges_rag.current_book,
|
| 286 |
"working_directory": os.getcwd(),
|
| 287 |
"directory_contents": [f for f in os.listdir('.') if os.path.isdir(f)],
|
| 288 |
+
"book_status": book_status,
|
| 289 |
+
"openai_api_key_configured": bool(os.getenv("OPENAI_API_KEY")),
|
| 290 |
+
"environment_variables": {k: "***" if "api" in k.lower() or "key" in k.lower() else v
|
| 291 |
+
for k, v in os.environ.items() if k.startswith(("OPENAI", "HF", "GRADIO"))},
|
| 292 |
}
|
| 293 |
|
| 294 |
+
# Add book instance info if available
|
| 295 |
+
if NANO_GRAPHRAG_AVAILABLE and borges_rag.current_book:
|
| 296 |
+
try:
|
| 297 |
+
book_instance = borges_rag.instances.get(borges_rag.current_book)
|
| 298 |
+
diagnostic_data["book_instance_loaded"] = book_instance is not None
|
| 299 |
+
if book_instance:
|
| 300 |
+
diagnostic_data["book_working_dir"] = getattr(book_instance, 'working_dir', 'Unknown')
|
| 301 |
+
except Exception as e:
|
| 302 |
+
diagnostic_data["book_instance_error"] = str(e)
|
| 303 |
+
|
| 304 |
+
return diagnostic_data
|
| 305 |
+
|
| 306 |
# Gradio app
|
| 307 |
with gr.Blocks(
|
| 308 |
title="Borges Graph - GraphRAG Explorer",
|
requirements.txt
CHANGED
|
@@ -6,4 +6,8 @@ openai>=1.0.0
|
|
| 6 |
networkx>=3.0
|
| 7 |
numpy>=1.21.0
|
| 8 |
tiktoken>=0.4.0
|
| 9 |
-
aiohttp>=3.8.0
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 6 |
networkx>=3.0
|
| 7 |
numpy>=1.21.0
|
| 8 |
tiktoken>=0.4.0
|
| 9 |
+
aiohttp>=3.8.0
|
| 10 |
+
python-dotenv
|
| 11 |
+
pandas
|
| 12 |
+
scikit-learn
|
| 13 |
+
sentence-transformers
|