Spaces:
Sleeping
Sleeping
Removed customization feature for now
Browse files
app.py
CHANGED
|
@@ -334,244 +334,248 @@ def load_existing_graph():
|
|
| 334 |
return jsonify({"error": str(e)}), 500
|
| 335 |
|
| 336 |
|
| 337 |
-
|
| 338 |
-
|
| 339 |
-
|
| 340 |
-
|
| 341 |
-
|
| 342 |
-
|
| 343 |
-
|
| 344 |
-
|
| 345 |
-
|
| 346 |
-
|
| 347 |
-
|
| 348 |
-
|
| 349 |
-
|
| 350 |
-
|
| 351 |
-
|
| 352 |
-
|
| 353 |
-
|
| 354 |
-
|
| 355 |
-
|
| 356 |
-
|
| 357 |
-
|
| 358 |
-
|
| 359 |
-
|
| 360 |
-
|
| 361 |
-
|
| 362 |
-
|
| 363 |
-
|
| 364 |
-
|
| 365 |
-
|
| 366 |
-
|
| 367 |
-
|
| 368 |
-
|
| 369 |
-
|
| 370 |
-
|
| 371 |
-
|
| 372 |
-
|
| 373 |
-
|
| 374 |
-
|
| 375 |
-
|
| 376 |
-
|
| 377 |
-
|
| 378 |
-
|
| 379 |
-
|
| 380 |
-
|
| 381 |
-
|
| 382 |
-
|
| 383 |
-
|
| 384 |
-
|
| 385 |
-
|
| 386 |
-
|
| 387 |
-
|
| 388 |
-
|
| 389 |
-
|
| 390 |
-
|
| 391 |
-
|
| 392 |
-
|
| 393 |
-
|
| 394 |
-
|
| 395 |
-
|
| 396 |
-
|
| 397 |
-
|
| 398 |
-
|
| 399 |
-
|
| 400 |
-
|
| 401 |
-
|
| 402 |
-
|
| 403 |
-
|
| 404 |
-
|
| 405 |
-
|
| 406 |
-
|
| 407 |
-
|
| 408 |
-
|
| 409 |
-
|
| 410 |
-
|
| 411 |
-
|
| 412 |
-
|
| 413 |
-
|
| 414 |
-
|
| 415 |
-
|
| 416 |
-
|
| 417 |
-
|
| 418 |
-
|
| 419 |
-
|
| 420 |
-
|
| 421 |
-
|
| 422 |
-
|
| 423 |
-
|
| 424 |
-
|
| 425 |
-
|
| 426 |
-
|
| 427 |
-
|
| 428 |
-
|
| 429 |
-
|
| 430 |
-
|
| 431 |
-
|
| 432 |
-
|
| 433 |
-
|
| 434 |
-
|
| 435 |
-
|
| 436 |
-
|
| 437 |
-
|
| 438 |
-
|
| 439 |
-
|
| 440 |
-
|
| 441 |
-
|
| 442 |
-
|
| 443 |
-
|
| 444 |
-
|
| 445 |
-
|
| 446 |
-
|
| 447 |
-
|
| 448 |
-
|
| 449 |
-
|
| 450 |
-
|
| 451 |
-
|
| 452 |
-
|
| 453 |
-
|
| 454 |
-
|
| 455 |
-
|
| 456 |
-
|
| 457 |
-
|
| 458 |
-
|
| 459 |
-
|
| 460 |
-
|
| 461 |
-
|
| 462 |
-
|
| 463 |
-
|
| 464 |
-
|
| 465 |
-
|
| 466 |
-
|
| 467 |
-
|
| 468 |
-
|
| 469 |
-
|
| 470 |
-
|
| 471 |
-
|
| 472 |
-
|
| 473 |
-
|
| 474 |
-
|
| 475 |
-
|
| 476 |
-
|
| 477 |
-
|
| 478 |
-
|
| 479 |
-
|
| 480 |
-
|
| 481 |
-
|
| 482 |
-
|
| 483 |
-
|
| 484 |
-
|
| 485 |
-
|
| 486 |
-
|
| 487 |
-
|
| 488 |
-
|
| 489 |
-
|
| 490 |
-
|
| 491 |
-
|
| 492 |
-
|
| 493 |
-
|
| 494 |
-
|
| 495 |
-
|
| 496 |
-
|
| 497 |
-
|
| 498 |
-
|
| 499 |
-
|
| 500 |
-
|
| 501 |
-
|
| 502 |
-
|
| 503 |
-
|
| 504 |
-
|
| 505 |
-
|
| 506 |
-
|
| 507 |
-
|
| 508 |
-
|
| 509 |
-
|
| 510 |
-
|
| 511 |
-
|
| 512 |
-
|
| 513 |
-
|
| 514 |
-
|
| 515 |
-
|
| 516 |
-
|
| 517 |
-
|
| 518 |
-
|
| 519 |
-
|
| 520 |
-
|
| 521 |
-
|
| 522 |
-
|
| 523 |
-
|
| 524 |
-
|
| 525 |
-
|
| 526 |
-
|
| 527 |
-
|
| 528 |
-
|
| 529 |
-
|
| 530 |
-
|
| 531 |
-
|
| 532 |
-
|
| 533 |
-
|
| 534 |
-
|
| 535 |
-
|
| 536 |
-
|
| 537 |
-
|
| 538 |
-
|
| 539 |
-
|
| 540 |
-
|
| 541 |
-
|
| 542 |
-
|
| 543 |
-
|
| 544 |
-
|
| 545 |
-
|
| 546 |
-
|
| 547 |
-
|
| 548 |
-
|
| 549 |
-
|
| 550 |
-
|
| 551 |
-
|
| 552 |
-
|
| 553 |
-
|
| 554 |
-
|
| 555 |
-
|
| 556 |
-
|
| 557 |
-
|
| 558 |
-
|
| 559 |
-
|
| 560 |
-
|
| 561 |
-
|
| 562 |
-
|
| 563 |
-
|
| 564 |
-
|
| 565 |
-
|
| 566 |
-
|
| 567 |
-
|
| 568 |
-
|
| 569 |
-
|
| 570 |
-
|
| 571 |
-
|
| 572 |
-
|
| 573 |
-
|
| 574 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 575 |
|
| 576 |
|
| 577 |
if __name__ == "__main__":
|
|
@@ -581,4 +585,4 @@ if __name__ == "__main__":
|
|
| 581 |
print(f"Repository root: {REPO_ROOT}")
|
| 582 |
print(f"Serving static files from: {os.path.join(REPO_ROOT, 'web_interface')}")
|
| 583 |
print(f"Open http://localhost:{port} in your browser")
|
| 584 |
-
app.run(debug=False, host="0.0.0.0", port=port)
|
|
|
|
| 334 |
return jsonify({"error": str(e)}), 500
|
| 335 |
|
| 336 |
|
| 337 |
+
# ============================================================================
|
| 338 |
+
# COMMENTED OUT: Create New Graph Feature - Disabled per user request
|
| 339 |
+
# ============================================================================
|
| 340 |
+
|
| 341 |
+
# @app.route("/api/create_graph", methods=["POST"])
|
| 342 |
+
# def create_graph():
|
| 343 |
+
# """Create a new POA graph from text sequences"""
|
| 344 |
+
# try:
|
| 345 |
+
# print("DEBUG: Received create_graph request")
|
| 346 |
+
# data = request.get_json()
|
| 347 |
+
# sequences = data.get("sequences", [])
|
| 348 |
+
#
|
| 349 |
+
# print(f"DEBUG: Number of sequences: {len(sequences)}")
|
| 350 |
+
#
|
| 351 |
+
# if len(sequences) < 2:
|
| 352 |
+
# return jsonify({"error": "At least 2 sequences are required"}), 400
|
| 353 |
+
#
|
| 354 |
+
# print("DEBUG: Creating initial graph")
|
| 355 |
+
# # Create the graph from first sequence
|
| 356 |
+
# graph = TextPOAGraph(sequences[0], label=0)
|
| 357 |
+
# print("DEBUG: Initial graph created")
|
| 358 |
+
#
|
| 359 |
+
# # Add remaining sequences
|
| 360 |
+
# for i, sequence in enumerate(sequences[1:], 1):
|
| 361 |
+
# print(f"DEBUG: Adding sequence {i}")
|
| 362 |
+
# alignment = TextSeqGraphAlignment(
|
| 363 |
+
# text=sequence,
|
| 364 |
+
# graph=graph,
|
| 365 |
+
# fastMethod=True,
|
| 366 |
+
# globalAlign=True,
|
| 367 |
+
# matchscore=1,
|
| 368 |
+
# mismatchscore=-2,
|
| 369 |
+
# gap_open=-1,
|
| 370 |
+
# )
|
| 371 |
+
# graph.incorporateSeqAlignment(alignment, sequence, label=i)
|
| 372 |
+
#
|
| 373 |
+
# print("DEBUG: All sequences added")
|
| 374 |
+
#
|
| 375 |
+
# # Refine the graph with proper domain and model parameters
|
| 376 |
+
# graph.refine_graph(verbose=False, domain="text", model="gpt-4o-mini")
|
| 377 |
+
# print("DEBUG: Graph refined")
|
| 378 |
+
#
|
| 379 |
+
# # Convert to JSON format for vis.js
|
| 380 |
+
# nodes = []
|
| 381 |
+
# edges = []
|
| 382 |
+
#
|
| 383 |
+
# try:
|
| 384 |
+
# print("DEBUG: Starting to process graph data")
|
| 385 |
+
# # Get consensus nodes for coloring (make it optional)
|
| 386 |
+
# try:
|
| 387 |
+
# consensus_nodes = set(graph.consensus_node_ids)
|
| 388 |
+
# print(f"DEBUG: Consensus nodes: {consensus_nodes}")
|
| 389 |
+
# except Exception as e:
|
| 390 |
+
# print(f"DEBUG: Error getting consensus nodes: {e}")
|
| 391 |
+
# consensus_nodes = set() # Fallback to empty set if consensus fails
|
| 392 |
+
#
|
| 393 |
+
# # Create nodes using the same logic as jsOutput
|
| 394 |
+
# for node in graph.nodeiterator()():
|
| 395 |
+
# title_text = ""
|
| 396 |
+
# if node.sequences:
|
| 397 |
+
# title_text += f"Sequences: {node.sequences}"
|
| 398 |
+
# if node.variations:
|
| 399 |
+
# title_text += ";;;".join(
|
| 400 |
+
# [f"{sequence_id}: {text}" for sequence_id, text in node.variations.items()]
|
| 401 |
+
# )
|
| 402 |
+
# title_text = title_text.replace('"', "'")
|
| 403 |
+
#
|
| 404 |
+
# # Use the same color logic as jsOutput
|
| 405 |
+
# color = "#ceeab2" if node.ID in consensus_nodes else "#cae0e6"
|
| 406 |
+
#
|
| 407 |
+
# node_data = {
|
| 408 |
+
# "id": node.ID,
|
| 409 |
+
# "label": f"{node.ID}: {node.text}",
|
| 410 |
+
# "title": title_text,
|
| 411 |
+
# "color": color,
|
| 412 |
+
# }
|
| 413 |
+
# nodes.append(node_data)
|
| 414 |
+
#
|
| 415 |
+
# print(f"DEBUG: Created {len(nodes)} nodes")
|
| 416 |
+
#
|
| 417 |
+
# # Create edges using the same logic as jsOutput
|
| 418 |
+
# for node in graph.nodeiterator()():
|
| 419 |
+
# nodeID = node.ID # Keep as integer
|
| 420 |
+
# for edge in node.outEdges:
|
| 421 |
+
# target = edge # Keep as integer
|
| 422 |
+
# weight = node.outEdges[edge].weight + 1.5
|
| 423 |
+
# edge_data = {
|
| 424 |
+
# "from": nodeID,
|
| 425 |
+
# "to": target,
|
| 426 |
+
# "value": weight,
|
| 427 |
+
# "color": "#cae0e6",
|
| 428 |
+
# "arrows": "to",
|
| 429 |
+
# }
|
| 430 |
+
# edges.append(edge_data)
|
| 431 |
+
#
|
| 432 |
+
# print(f"DEBUG: Created {len(edges)} edges")
|
| 433 |
+
# except Exception as e:
|
| 434 |
+
# print(f"DEBUG: Error processing graph data: {e}")
|
| 435 |
+
# return jsonify({"error": f"Error processing graph data: {str(e)}"}), 500
|
| 436 |
+
#
|
| 437 |
+
# # Extract text from consensus nodes
|
| 438 |
+
# consensus_text = ""
|
| 439 |
+
# try:
|
| 440 |
+
# consensus_node_texts = []
|
| 441 |
+
# for node in graph.nodeiterator()():
|
| 442 |
+
# if node.ID in consensus_nodes and node.text and node.text.strip():
|
| 443 |
+
# consensus_node_texts.append(node.text.strip())
|
| 444 |
+
# consensus_text = " ".join(consensus_node_texts)
|
| 445 |
+
# except Exception:
|
| 446 |
+
# consensus_text = ""
|
| 447 |
+
#
|
| 448 |
+
# # Check if we should compute consensus using decode_consensus
|
| 449 |
+
# compute_consensus = data.get("compute_consensus", False)
|
| 450 |
+
# if compute_consensus and decode_consensus:
|
| 451 |
+
# try:
|
| 452 |
+
# # Default to "bio" task for new graphs
|
| 453 |
+
# consensus_text = decode_consensus(graph, selection_threshold=0.5, task="bio")
|
| 454 |
+
# except Exception as e:
|
| 455 |
+
# print(f"DEBUG: Error computing consensus with decode_consensus: {e}")
|
| 456 |
+
# # Keep the original consensus text if decode_consensus fails
|
| 457 |
+
#
|
| 458 |
+
# # Get original sequences
|
| 459 |
+
# try:
|
| 460 |
+
# raw_sequences = graph._seqs if hasattr(graph, "_seqs") else []
|
| 461 |
+
# # Process sequences: join with spaces and remove "||"
|
| 462 |
+
# original_sequences = []
|
| 463 |
+
# for seq in raw_sequences:
|
| 464 |
+
# if isinstance(seq, list):
|
| 465 |
+
# # Join list elements with spaces
|
| 466 |
+
# processed_seq = " ".join(str(item) for item in seq)
|
| 467 |
+
# else:
|
| 468 |
+
# processed_seq = str(seq)
|
| 469 |
+
# # Remove "||" characters
|
| 470 |
+
# processed_seq = processed_seq.replace("||", "")
|
| 471 |
+
# original_sequences.append(processed_seq)
|
| 472 |
+
# except Exception:
|
| 473 |
+
# original_sequences = []
|
| 474 |
+
#
|
| 475 |
+
# print("DEBUG: Returning success response")
|
| 476 |
+
# return jsonify(
|
| 477 |
+
# {
|
| 478 |
+
# "success": True,
|
| 479 |
+
# "nodes": nodes,
|
| 480 |
+
# "edges": edges,
|
| 481 |
+
# "num_sequences": len(sequences),
|
| 482 |
+
# "num_nodes": len(nodes),
|
| 483 |
+
# "num_edges": len(edges),
|
| 484 |
+
# "original_sequences": original_sequences,
|
| 485 |
+
# "consensus_text": consensus_text,
|
| 486 |
+
# }
|
| 487 |
+
# )
|
| 488 |
+
#
|
| 489 |
+
# except Exception as e:
|
| 490 |
+
# print(f"DEBUG: Main exception in create_graph: {e}")
|
| 491 |
+
# return jsonify({"error": str(e)}), 500
|
| 492 |
+
|
| 493 |
+
|
| 494 |
+
# @app.route("/api/save_graph", methods=["POST"])
|
| 495 |
+
# def save_graph():
|
| 496 |
+
# """Save a POA graph to a pickle file"""
|
| 497 |
+
# try:
|
| 498 |
+
# data = request.get_json()
|
| 499 |
+
# sequences = data.get("sequences", [])
|
| 500 |
+
# filename = data.get("filename", "graph.pkl")
|
| 501 |
+
#
|
| 502 |
+
# if len(sequences) < 2:
|
| 503 |
+
# return jsonify({"error": "At least 2 sequences are required"}), 400
|
| 504 |
+
#
|
| 505 |
+
# # Create the graph
|
| 506 |
+
# graph = TextPOAGraph(sequences[0], label=0)
|
| 507 |
+
#
|
| 508 |
+
# # Add remaining sequences
|
| 509 |
+
# for i, sequence in enumerate(sequences[1:], 1):
|
| 510 |
+
# alignment = TextSeqGraphAlignment(
|
| 511 |
+
# text=sequence,
|
| 512 |
+
# graph=graph,
|
| 513 |
+
# fastMethod=True,
|
| 514 |
+
# globalAlign=True,
|
| 515 |
+
# matchscore=1,
|
| 516 |
+
# mismatchscore=-2,
|
| 517 |
+
# gap_open=-1,
|
| 518 |
+
# )
|
| 519 |
+
# graph.incorporateSeqAlignment(alignment, sequence, label=i)
|
| 520 |
+
#
|
| 521 |
+
# # Refine the graph
|
| 522 |
+
# graph.refine_graph(verbose=False)
|
| 523 |
+
#
|
| 524 |
+
# # Save to pickle file
|
| 525 |
+
# graph.save_to_pickle(filename)
|
| 526 |
+
#
|
| 527 |
+
# return jsonify(
|
| 528 |
+
# {"success": True, "filename": filename, "message": f"Graph saved to {filename}"}
|
| 529 |
+
# )
|
| 530 |
+
#
|
| 531 |
+
# except Exception as e:
|
| 532 |
+
# return jsonify({"error": str(e)}), 500
|
| 533 |
+
|
| 534 |
+
|
| 535 |
+
# @app.route("/api/graph_info", methods=["POST"])
|
| 536 |
+
# def graph_info():
|
| 537 |
+
# """Get information about a graph without creating the full visualization"""
|
| 538 |
+
# try:
|
| 539 |
+
# data = request.get_json()
|
| 540 |
+
# sequences = data.get("sequences", [])
|
| 541 |
+
#
|
| 542 |
+
# if len(sequences) < 2:
|
| 543 |
+
# return jsonify({"error": "At least 2 sequences are required"}), 400
|
| 544 |
+
#
|
| 545 |
+
# # Create the graph
|
| 546 |
+
# graph = TextPOAGraph(sequences[0], label=0)
|
| 547 |
+
#
|
| 548 |
+
# # Add remaining sequences
|
| 549 |
+
# for i, sequence in enumerate(sequences[1:], 1):
|
| 550 |
+
# alignment = TextSeqGraphAlignment(
|
| 551 |
+
# text=sequence,
|
| 552 |
+
# graph=graph,
|
| 553 |
+
# fastMethod=True,
|
| 554 |
+
# globalAlign=True,
|
| 555 |
+
# matchscore=1,
|
| 556 |
+
# mismatchscore=-2,
|
| 557 |
+
# gap_open=-1,
|
| 558 |
+
# )
|
| 559 |
+
# graph.incorporateSeqAlignment(alignment, sequence, label=i)
|
| 560 |
+
#
|
| 561 |
+
# # Refine the graph
|
| 562 |
+
# graph.refine_graph(verbose=False)
|
| 563 |
+
#
|
| 564 |
+
# # Get consensus response
|
| 565 |
+
# consensus_text = graph.consensus_response()
|
| 566 |
+
#
|
| 567 |
+
# return jsonify(
|
| 568 |
+
# {
|
| 569 |
+
# "success": True,
|
| 570 |
+
# "num_sequences": len(sequences),
|
| 571 |
+
# "num_nodes": graph._nnodes,
|
| 572 |
+
# "consensus_text": consensus_text,
|
| 573 |
+
# "consensus_node_ids": graph.consensus_node_ids,
|
| 574 |
+
# }
|
| 575 |
+
# )
|
| 576 |
+
#
|
| 577 |
+
# except Exception as e:
|
| 578 |
+
# return jsonify({"error": str(e)}), 500
|
| 579 |
|
| 580 |
|
| 581 |
if __name__ == "__main__":
|
|
|
|
| 585 |
print(f"Repository root: {REPO_ROOT}")
|
| 586 |
print(f"Serving static files from: {os.path.join(REPO_ROOT, 'web_interface')}")
|
| 587 |
print(f"Open http://localhost:{port} in your browser")
|
| 588 |
+
app.run(debug=False, host="0.0.0.0", port=port)
|