bano1 commited on
Commit
d404481
·
verified ·
1 Parent(s): 096877b

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +38 -8
app.py CHANGED
@@ -52,22 +52,36 @@ def extract_title(text):
52
  return line
53
  return "Untitled"
54
 
55
-
56
  def extract_authors(text):
57
- """Heuristic: detect names between title and abstract/keywords."""
58
  lines = text.split("\n")
59
  authors = []
60
  found_title = False
 
61
  for line in lines:
62
  line = line.strip()
 
63
  if not found_title and len(line.split()) >= 5:
64
  found_title = True
65
  continue
 
 
66
  if found_title:
67
  if "abstract" in line.lower() or "keywords" in line.lower():
68
  break
69
- if re.match(r"^[A-Z][a-z]+(\s[A-Z]\.)?(\s[A-Z][a-z]+)+$", line):
70
- authors.append(line)
 
 
 
 
 
 
 
 
 
 
 
71
  return authors if authors else ["Unknown"]
72
 
73
 
@@ -177,29 +191,45 @@ def generate_wordcloud(papers):
177
 
178
  def build_coauthor_graph(papers):
179
  G = nx.Graph()
 
180
  for p in papers:
181
  authors = p.get("authors", ["Unknown"])
 
 
 
 
 
 
182
  for i in range(len(authors)):
183
  for j in range(i+1, len(authors)):
184
  G.add_edge(authors[i], authors[j])
185
- pos = nx.spring_layout(G)
 
 
 
 
 
186
  edge_x, edge_y, node_x, node_y, text = [], [], [], [], []
 
187
  for edge in G.edges():
188
  x0, y0 = pos[edge[0]]
189
  x1, y1 = pos[edge[1]]
190
  edge_x.extend([x0, x1, None])
191
  edge_y.extend([y0, y1, None])
 
192
  for node in G.nodes():
193
  x, y = pos[node]
194
  node_x.append(x); node_y.append(y)
195
  text.append(node)
 
196
  fig = go.Figure()
197
- fig.add_trace(go.Scatter(x=edge_x, y=edge_y, line=dict(width=0.5,color='#888'),
 
198
  hoverinfo='none', mode='lines'))
199
  fig.add_trace(go.Scatter(x=node_x, y=node_y, mode='markers+text',
200
  text=text, textposition="top center",
201
- marker=dict(size=10, color='skyblue')))
202
- st.plotly_chart(fig)
203
 
204
  def export_bibtex(papers):
205
  db = {"entries": []}
 
52
  return line
53
  return "Untitled"
54
 
 
55
  def extract_authors(text):
56
+ """Detect author names between title and abstract/keywords."""
57
  lines = text.split("\n")
58
  authors = []
59
  found_title = False
60
+
61
  for line in lines:
62
  line = line.strip()
63
+ # Step 1: title detect karo
64
  if not found_title and len(line.split()) >= 5:
65
  found_title = True
66
  continue
67
+
68
+ # Step 2: Stop at abstract/keywords
69
  if found_title:
70
  if "abstract" in line.lower() or "keywords" in line.lower():
71
  break
72
+
73
+ # Step 3: Agar line me multiple authors hain
74
+ if "," in line or " and " in line.lower():
75
+ parts = re.split(",| and ", line)
76
+ for name in parts:
77
+ name = name.strip()
78
+ if re.match(r"^[A-Z][a-z]+(\s[A-Z]\.?\s?[A-Z][a-z]+)?$", name):
79
+ authors.append(name)
80
+ else:
81
+ # single name line
82
+ if re.match(r"^[A-Z][a-z]+(\s[A-Z]\.?\s?[A-Z][a-z]+)?$", line):
83
+ authors.append(line)
84
+
85
  return authors if authors else ["Unknown"]
86
 
87
 
 
191
 
192
  def build_coauthor_graph(papers):
193
  G = nx.Graph()
194
+
195
  for p in papers:
196
  authors = p.get("authors", ["Unknown"])
197
+
198
+ # Ensure every author at least ek node ban jaye
199
+ for a in authors:
200
+ G.add_node(a)
201
+
202
+ # Edges sirf jab ≥2 authors ho
203
  for i in range(len(authors)):
204
  for j in range(i+1, len(authors)):
205
  G.add_edge(authors[i], authors[j])
206
+
207
+ if len(G.nodes) == 0:
208
+ st.warning("No author data found.")
209
+ return
210
+
211
+ pos = nx.spring_layout(G, seed=42)
212
  edge_x, edge_y, node_x, node_y, text = [], [], [], [], []
213
+
214
  for edge in G.edges():
215
  x0, y0 = pos[edge[0]]
216
  x1, y1 = pos[edge[1]]
217
  edge_x.extend([x0, x1, None])
218
  edge_y.extend([y0, y1, None])
219
+
220
  for node in G.nodes():
221
  x, y = pos[node]
222
  node_x.append(x); node_y.append(y)
223
  text.append(node)
224
+
225
  fig = go.Figure()
226
+ fig.add_trace(go.Scatter(x=edge_x, y=edge_y,
227
+ line=dict(width=0.5, color='#888'),
228
  hoverinfo='none', mode='lines'))
229
  fig.add_trace(go.Scatter(x=node_x, y=node_y, mode='markers+text',
230
  text=text, textposition="top center",
231
+ marker=dict(size=12, color='skyblue')))
232
+ st.plotly_chart(fig, use_container_width=True)
233
 
234
  def export_bibtex(papers):
235
  db = {"entries": []}