EchaRz commited on
Commit
3d76f46
·
1 Parent(s): 921e201

Add explanation

Browse files
Files changed (2) hide show
  1. FlowExplanation.png +0 -0
  2. app.py +4 -11
FlowExplanation.png ADDED
app.py CHANGED
@@ -1,9 +1,6 @@
1
  import sqlite3
2
  import contextlib
3
  import json
4
- from http.server import BaseHTTPRequestHandler
5
- from urllib.parse import urlparse, parse_qs
6
- import traceback
7
  from pydantic import BaseModel, Field
8
  from typing import List, Dict, Tuple, Optional
9
  import os
@@ -23,7 +20,6 @@ app = FastAPI(title="Knowledge Graph API")
23
 
24
  app.mount("/static", StaticFiles(directory="static"), name="static")
25
 
26
- # Enable CORS for frontend access
27
  app.add_middleware(
28
  CORSMiddleware,
29
  allow_origins=["*"],
@@ -255,8 +251,6 @@ def extract_information_from_triplets(query: str,
255
  triplets: List[Tuple[str, str, str]],
256
  relations: List[Tuple[str, str]]) -> str:
257
  """
258
- REPLACE THIS FUNCTION WITH YOUR ACTUAL IMPLEMENTATION
259
-
260
  Args:
261
  triplets: List of triplets from retrieve_triplets
262
  relations: List of relation definitions from retrieve_triplets
@@ -476,7 +470,7 @@ def serve_search_page():
476
 
477
  @app.post("/api/query", response_model=QueryResponse)
478
  def process_query(request: QueryRequest):
479
- """Process user query and return comprehensive response"""
480
  try:
481
  # Step 1: Retrieve triplets
482
  query = request.query
@@ -521,7 +515,6 @@ def process_query(request: QueryRequest):
521
  nodes_set.add(head)
522
  nodes_set.add(tail)
523
 
524
- # Find definition for this relation
525
  definition = "No definition available"
526
  for rel, def_text in relations_data:
527
  if rel == relation:
@@ -554,7 +547,7 @@ def process_query(request: QueryRequest):
554
  def get_graph_data(
555
  search: Optional[str] = None
556
  ):
557
- """Get complete graph data with nodes and edges."""
558
 
559
  try:
560
  # Build dynamic query based on configuration
@@ -577,9 +570,9 @@ def get_graph_data(
577
  with get_triplets_db() as conn:
578
  cursor = conn.execute(base_query, params)
579
  triplets = cursor.fetchall()
580
-
 
581
  with get_definitions_db() as conn:
582
- # Get definitions
583
  def_table = DATABASE_CONFIG["definitions_table"]
584
  def_col = DATABASE_CONFIG["definition_column"]
585
  rel_col_def = DATABASE_CONFIG["relation_column"]
 
1
  import sqlite3
2
  import contextlib
3
  import json
 
 
 
4
  from pydantic import BaseModel, Field
5
  from typing import List, Dict, Tuple, Optional
6
  import os
 
20
 
21
  app.mount("/static", StaticFiles(directory="static"), name="static")
22
 
 
23
  app.add_middleware(
24
  CORSMiddleware,
25
  allow_origins=["*"],
 
251
  triplets: List[Tuple[str, str, str]],
252
  relations: List[Tuple[str, str]]) -> str:
253
  """
 
 
254
  Args:
255
  triplets: List of triplets from retrieve_triplets
256
  relations: List of relation definitions from retrieve_triplets
 
470
 
471
  @app.post("/api/query", response_model=QueryResponse)
472
  def process_query(request: QueryRequest):
473
+ """Process user query and return response"""
474
  try:
475
  # Step 1: Retrieve triplets
476
  query = request.query
 
515
  nodes_set.add(head)
516
  nodes_set.add(tail)
517
 
 
518
  definition = "No definition available"
519
  for rel, def_text in relations_data:
520
  if rel == relation:
 
547
  def get_graph_data(
548
  search: Optional[str] = None
549
  ):
550
+ """Get complete graph data for explore page"""
551
 
552
  try:
553
  # Build dynamic query based on configuration
 
570
  with get_triplets_db() as conn:
571
  cursor = conn.execute(base_query, params)
572
  triplets = cursor.fetchall()
573
+
574
+ # Get definitions
575
  with get_definitions_db() as conn:
 
576
  def_table = DATABASE_CONFIG["definitions_table"]
577
  def_col = DATABASE_CONFIG["definition_column"]
578
  rel_col_def = DATABASE_CONFIG["relation_column"]