madhurjindal commited on
Commit
bf25b85
1 Parent(s): b054afc

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +122 -0
app.py ADDED
@@ -0,0 +1,122 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from langgraph.graph import END, START, StateGraph
2
+
3
+ from langchain_core.tracers.context import tracing_v2_enabled
4
+
5
+ from prompts import *
6
+ import gradio as gr
7
+
8
+
9
+ from utils import (
10
+ load_github_codebase,
11
+ router,
12
+ get_plan_for_codebase,
13
+ parse_plan,
14
+ explore_file,
15
+ final_mermaid_code_generation,
16
+ extract_mermaid_and_generate_graph,
17
+ GraphState,
18
+ )
19
+
20
+
21
+ def visualize_github_repo(repo_name, repo_branch):
22
+ yield ("Looking at the Repo!", None)
23
+ documents = load_github_codebase(repo_name, repo_branch)
24
+ yield ("Repo loaded!", None)
25
+
26
+ # Define a new graph
27
+ workflow = StateGraph(GraphState)
28
+
29
+ # Define the two nodes we will cycle
30
+ workflow.add_node("planner", get_plan_for_codebase)
31
+ workflow.add_node("parse_plan", parse_plan)
32
+
33
+ workflow.add_node("explore_file", explore_file)
34
+ workflow.add_node("router", router)
35
+
36
+ workflow.add_node("generate_mermaid_code", final_mermaid_code_generation)
37
+ workflow.add_node("render_mermaid", extract_mermaid_and_generate_graph)
38
+
39
+ # Set the entrypoint as `agent`
40
+ # This means that this node is the first one called
41
+ workflow.add_edge(START, "planner")
42
+ workflow.add_edge("planner", "parse_plan")
43
+
44
+ # We now add a conditional edge
45
+ workflow.add_conditional_edges(
46
+ # First, we define the start node. We use `agent`.
47
+ # This means these are the edges taken after the `agent` node is called.
48
+ "parse_plan",
49
+ # Next, we pass in the function that will determine which node is called next.
50
+ router,
51
+ )
52
+ workflow.add_conditional_edges(
53
+ "explore_file",
54
+ router,
55
+ )
56
+ workflow.add_edge("generate_mermaid_code", "render_mermaid")
57
+ workflow.add_edge("render_mermaid", END)
58
+
59
+ # Finally, we compile it!
60
+ # This compiles it into a LangChain Runnable,
61
+ # meaning you can use it as you would any other runnable.
62
+ # Note that we're (optionally) passing the memory when compiling the graph
63
+ app = workflow.compile()
64
+
65
+ with tracing_v2_enabled():
66
+ for s in app.stream(
67
+ {"messages": [], "documents": documents},
68
+ {"recursion_limit": 100},
69
+ ):
70
+ if "__end__" not in s:
71
+ print(s)
72
+ print("----")
73
+ if "planner" in s:
74
+ yield ("Planning the Exploration !", None)
75
+ if "parse_plan" in s:
76
+ yield ("Planning done! Parsing the plan!", None)
77
+ if "explore_file" in s:
78
+ yield (
79
+ f"Exploration started! Exploring file: {s['explore_file']['explored_files'][-1]} !",
80
+ None,
81
+ )
82
+ if "generate_mermaid_code" in s:
83
+ yield (
84
+ "Exploration done! Gathering thoughts and generating a graph!",
85
+ None,
86
+ )
87
+ if "render_mermaid" in s:
88
+
89
+ yield (
90
+ s["render_mermaid"]["messages"][-1].content,
91
+ s["render_mermaid"]["final_graph"],
92
+ )
93
+
94
+
95
+ demo = gr.Interface(
96
+ fn=visualize_github_repo,
97
+ inputs=[
98
+ gr.Textbox(
99
+ label="Repo Name", # Input component label
100
+ value="abhishekkrthakur/autoxgb", # Input component placeholder
101
+ placeholder="Name of the Repo in format author/repo", # Input component description
102
+ ),
103
+ gr.Textbox(
104
+ label="Repo Branch", # Input component label
105
+ value="main", # Input component placeholder
106
+ placeholder="Branch to explore", # Input component description
107
+ ),
108
+ ],
109
+ outputs=[
110
+ gr.Textbox(
111
+ label="Mermaid Graph", # Output component label
112
+ placeholder="Visualization of the functionalities of the Repo", # Output component description
113
+ ),
114
+ gr.Image(
115
+ label="Rendered Graph", # Output component label
116
+ placeholder="Rendered Graph", # Output component description
117
+ ),
118
+ ],
119
+ title="Repo Functionality Visualizer",
120
+ )
121
+
122
+ demo.launch()