File size: 2,999 Bytes
e6583bf
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
from shared import ResearchState
from graph_article.graph_article import article_graph
from graph_web.graph_web import web_graph
from dotenv import load_dotenv
from graph_web.search import DEFAULT_URL
from pydantic import ValidationError
from utils.visualizer import graph_visualiser
# Import evaluation tool
from utils.evaluation import evaluate_abstract  

import os
load_dotenv('.env')  # Load environment variables

LANGSMITH_API_KEY = os.getenv("LANGSMITH_API_KEY")
LANGSMITH_TRACING = os.getenv("LANGSMITH_TRACING")
LANGSMITH_PROJECT = os.getenv("LANGSMITH_PROJECT")
LANGSMITH_ENDPOINT = os.getenv("LANGSMITH_ENDPOINT")

def main():
    print("=== Welcome to the LangGraph Research Assistant ===")

    while True:
        print("\nSelect a task to perform:")
        print("1. Generate Research Abstract")
        print("2. Summarize Webpages")
        print("3. Exit")

        choice = input("Enter your choice (1/2/3): ").strip()

        if choice == "1":
            title = input("Enter research title: ")
            category = input("Enter category: ")
            init_state = ResearchState(input=title, category=category)
            final_state = article_graph.invoke(init_state)

            if final_state.get("final_abstract"):
                print("\n--- βœ… Final Abstract ---")
                print(final_state["final_abstract"])

                # 🧠 Run Evaluation
                evaluation = evaluate_abstract(final_state["final_abstract"])
                print("\n--- πŸ“Š Evaluation ---")
                print(f"Word Count: {evaluation['word_count']}")
                print(f"Keyword Match Score: {evaluation['keyword_match_score']}")
                print(f"Keywords Present: {', '.join(evaluation['keywords_present'])}")

            else:
                print("\n❌ No final abstract was accepted by the critic.")

        elif choice == "2":
            print("\nπŸ“„ Web Summarizer Mode (Press Enter to exit anytime)")
            while True:
                user_input = input(f"\nEnter a URL to summarize [default: {DEFAULT_URL}]: ").strip()
                if not user_input:
                    print("πŸ”š Returning to main menu...")
                    break

                try:
                    init_state = ResearchState(url=user_input)
                    final_state = web_graph.invoke(init_state)
                    print("\n--- Webpage Summary ---")
                    print(final_state["summary"])
                except ValidationError as e:
                    print(f"❌ Invalid URL: {e}")

        elif choice == "3":
            print("πŸ‘‹ Goodbye!")
            break

        else:
            print("❌ Invalid input. Try again.")

if __name__ == "__main__":
    # Optional: visualize LangGraphs
    graph_visualiser(web_graph, filename="visuals/web_graph.jpg")
    graph_visualiser(article_graph, filename="visuals/article_graph.jpg")

    main()