rahull30 commited on
Commit
5607d95
·
verified ·
1 Parent(s): e351e96

updated app.py for graphs

Browse files
Files changed (1) hide show
  1. app.py +74 -11
app.py CHANGED
@@ -1,28 +1,87 @@
1
  import gradio as gr
2
  from agent import ResearchAgent
 
 
 
 
3
 
4
  agent = ResearchAgent()
5
 
6
  def run_pipeline(file):
7
  try:
8
  if file is None:
9
- return "Upload a CSV file", None, None, None, None
10
 
11
- result = agent.execute_pipeline(file.name)
 
 
 
12
 
13
  if "error" in result:
14
- return result["error"], None, None, None, None
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
15
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
16
  return (
17
  "✅ Pipeline completed",
18
  "comparison.csv",
19
  "taxonomy_map.json",
20
  "topic_review_table.csv",
21
- "keywords.csv"
 
 
 
 
22
  )
23
 
24
  except Exception as e:
25
- return str(e), None, None, None, None
26
 
27
 
28
  demo = gr.Interface(
@@ -30,12 +89,16 @@ demo = gr.Interface(
30
  inputs=gr.File(label="Upload CSV"),
31
  outputs=[
32
  gr.Textbox(label="Status"),
33
- gr.File(label="Download comparison.csv"),
34
- gr.File(label="Download taxonomy_map.json"),
35
- gr.File(label="Download topic_review_table.csv"),
36
- gr.File(label="Download keywords.csv"),
 
 
 
 
37
  ],
38
- title="Topic Modeling App"
39
  )
40
 
41
- demo.launch()
 
1
  import gradio as gr
2
  from agent import ResearchAgent
3
+ import pandas as pd
4
+ import matplotlib.pyplot as plt
5
+ import json
6
+ import tempfile
7
 
8
  agent = ResearchAgent()
9
 
10
  def run_pipeline(file):
11
  try:
12
  if file is None:
13
+ return "Upload CSV", None, None, None, None, None, None, None, None
14
 
15
+ # Save temp file
16
+ path = file.name
17
+
18
+ result = agent.execute_pipeline(path)
19
 
20
  if "error" in result:
21
+ return result["error"], None, None, None, None, None, None, None, None
22
+
23
+ # Load outputs
24
+ comp = pd.read_csv("comparison.csv")
25
+ topic = pd.read_csv("topic_review_table.csv")
26
+ keywords = pd.read_csv("keywords.csv")
27
+
28
+ with open("taxonomy_map.json") as f:
29
+ taxonomy = json.load(f)
30
+
31
+ import plotly.express as px
32
+
33
+ # -------- Graph 1: similarity distribution --------
34
+ fig1 = px.histogram(
35
+ comp,
36
+ x="similarity_score",
37
+ nbins=30,
38
+ title="Title vs Abstract Similarity Distribution",
39
+ )
40
+ fig1.update_layout(xaxis_title="Similarity Score", yaxis_title="Frequency")
41
+
42
+ # -------- Graph 2: topic importance --------
43
+ top_topics = topic.sort_values("document_count", ascending=False).head(15)
44
 
45
+ fig2 = px.bar(
46
+ top_topics,
47
+ x="topic_id",
48
+ y="document_count",
49
+ title="Top 15 Topics by Document Coverage",
50
+ )
51
+
52
+ # -------- Graph 3: keyword relevance --------
53
+ top_keywords = keywords.sort_values("relevance", ascending=False).head(15)
54
+
55
+ fig3 = px.bar(
56
+ top_keywords,
57
+ x="ID",
58
+ y="relevance",
59
+ title="Top Keyword Clusters by Relevance",
60
+ )
61
+
62
+ # -------- Graph 4: mapping insight --------
63
+ mapped = len(taxonomy["mapped"])
64
+ novel = len(taxonomy["novel"])
65
+
66
+ fig4 = px.pie(
67
+ names=["Mapped", "Novel"],
68
+ values=[mapped, novel],
69
+ title="Knowledge Mapping: Known vs Novel Themes",
70
+ )
71
  return (
72
  "✅ Pipeline completed",
73
  "comparison.csv",
74
  "taxonomy_map.json",
75
  "topic_review_table.csv",
76
+ "keywords.csv",
77
+ "comp_plot.png",
78
+ "topic_plot.png",
79
+ "keywords_plot.png",
80
+ "taxonomy_plot.png"
81
  )
82
 
83
  except Exception as e:
84
+ return str(e), None, None, None, None, None, None, None, None
85
 
86
 
87
  demo = gr.Interface(
 
89
  inputs=gr.File(label="Upload CSV"),
90
  outputs=[
91
  gr.Textbox(label="Status"),
92
+ gr.File(label="comparison.csv"),
93
+ gr.File(label="taxonomy_map.json"),
94
+ gr.File(label="topic_review_table.csv"),
95
+ gr.File(label="keywords.csv"),
96
+ gr.Image(label="Similarity Graph"),
97
+ gr.Image(label="Topic Distribution"),
98
+ gr.Image(label="Keyword Relevance"),
99
+ gr.Image(label="Mapping Graph"),
100
  ],
101
+ title="Topic Modeling Dashboard"
102
  )
103
 
104
+ demo.launch(share=True)