Subahdip627 commited on
Commit
5b882f5
·
verified ·
1 Parent(s): 3a9fe32

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +71 -89
app.py CHANGED
@@ -136,49 +136,31 @@ button.variant-secondary {
136
  border-radius: 6px !important;
137
  }
138
 
139
- /* ================================================= */
140
- /* PERFECT DROPDOWN POPUP FIX (NO BLACK / NO WHITE) */
141
- /* ================================================= */
142
-
143
- /* Target HeadlessUI portal */
144
- div[id^="headlessui-portal"] {
145
- background: transparent !important;
146
- }
147
-
148
- /* Dropdown container */
149
- div[id^="headlessui-portal"] div[role="listbox"] {
150
- background-color: #f3f4f6 !important;
151
- border: 1px solid #d1d5db !important;
152
- box-shadow: 0 8px 24px rgba(0,0,0,0.15) !important;
153
- border-radius: 8px !important;
154
- overflow: hidden !important;
155
  }
156
 
157
- /* All options */
158
- div[id^="headlessui-portal"] div[role="option"] {
159
- background-color: #f3f4f6 !important;
160
- color: #111827 !important;
161
- padding: 10px 14px !important;
162
- }
163
-
164
- /* Hover state */
165
- div[id^="headlessui-portal"] div[role="option"]:hover {
166
- background-color: #e5e7eb !important;
167
- color: #111827 !important;
168
  }
169
 
170
- /* Selected option (strong override) */
171
- div[id^="headlessui-portal"] div[role="option"][aria-selected="true"],
172
- div[id^="headlessui-portal"] div[role="option"].selected,
173
- div[id^="headlessui-portal"] div[role="option"][data-headlessui-state~="selected"] {
174
- background-color: #2563eb !important;
175
- color: #ffffff !important;
176
  }
177
 
178
- /* Fix checkmark icon color */
179
- div[id^="headlessui-portal"] svg {
180
  color: #ffffff !important;
181
- fill: #ffffff !important;
182
  }
183
  /* ================================================= */
184
  /* METRIC LABEL BLACK BACKGROUND */
@@ -233,7 +215,7 @@ class PaperSearchPro:
233
  filters.append(f"publication_year:<{int(year_to)+1}")
234
  if open_access:
235
  filters.append("open_access.is_oa:true")
236
-
237
  # Add author filter if provided
238
  if authors and authors.strip():
239
  # Clean and format author names for filtering
@@ -320,7 +302,7 @@ class PaperSearchPro:
320
  # Sort by relevance score (our calculated score)
321
  filtered.sort(key=lambda x: x["Relevance"], reverse=True)
322
  all_papers = filtered[:max_papers]
323
-
324
  # ===============================
325
  # AUTHOR FILTERING (post-API)
326
  # ===============================
@@ -328,24 +310,24 @@ class PaperSearchPro:
328
  # If we have author filter but no keyword hierarchy
329
  author_list = [a.strip().lower() for a in authors.split(",") if a.strip()]
330
  filtered = []
331
-
332
  for p in all_papers:
333
  all_authors_lower = p['All Authors'].lower()
334
  match_all = True
335
  matched_authors = []
336
-
337
  for author in author_list:
338
  if author in all_authors_lower:
339
  matched_authors.append(author)
340
  else:
341
  match_all = False
342
  break
343
-
344
  if match_all:
345
  p["Relevance"] = len(matched_authors)
346
  p["Matched Keywords"] = f"Authors: {', '.join(matched_authors)}"
347
  filtered.append(p)
348
-
349
  all_papers = filtered[:max_papers]
350
 
351
  total = len(all_papers)
@@ -354,24 +336,24 @@ class PaperSearchPro:
354
  year_range = f"{min(years)} - {max(years)}" if years else "N/A"
355
 
356
  df = pd.DataFrame(all_papers)
357
-
358
  # Reorder columns to include BibTeX and remove All Authors from display
359
- column_order = ['Title', 'Authors', 'Year', 'Citations', 'Journal', 'Abstract',
360
  'BibTeX', 'Relevance', 'Matched Keywords']
361
  df = df[column_order]
362
 
363
  return df, all_papers, total, avg_rel, year_range
364
-
365
  def search_specific_paper(self, search_type, search_value):
366
  """Search for a specific paper by title, author, or DOI"""
367
-
368
  all_papers = []
369
-
370
  if search_type == "DOI":
371
  # Clean DOI (remove URL if present)
372
  if "doi.org/" in search_value:
373
  search_value = search_value.split("doi.org/")[-1]
374
-
375
  # Direct lookup by DOI
376
  url = f"https://api.openalex.org/works/doi/{search_value}"
377
  try:
@@ -382,7 +364,7 @@ class PaperSearchPro:
382
  all_papers.append(paper)
383
  except Exception as e:
384
  print(f"Error fetching DOI: {e}")
385
-
386
  elif search_type == "Exact Title":
387
  # Search by exact title
388
  params = {
@@ -394,7 +376,7 @@ class PaperSearchPro:
394
  response = requests.get(self.base_url, params=params, timeout=15)
395
  data = response.json()
396
  results = data.get("results", [])
397
-
398
  for work in results:
399
  # Check for close title match
400
  title = work.get("title", "").lower()
@@ -404,7 +386,7 @@ class PaperSearchPro:
404
  break # Take the first good match
405
  except Exception as e:
406
  print(f"Error searching title: {e}")
407
-
408
  elif search_type == "Specific Author":
409
  # Search for papers by a specific author
410
  params = {
@@ -417,26 +399,26 @@ class PaperSearchPro:
417
  response = requests.get(self.base_url, params=params, timeout=15)
418
  data = response.json()
419
  results = data.get("results", [])
420
-
421
  for work in results[:20]: # Limit to 20 papers
422
  paper = self.extract_info(work)
423
  all_papers.append(paper)
424
  except Exception as e:
425
  print(f"Error searching author: {e}")
426
-
427
  if all_papers:
428
  for i, p in enumerate(all_papers):
429
  p['Rank'] = i + 1
430
-
431
  df = pd.DataFrame(all_papers)
432
  column_order = ['Title', 'Authors', 'Year', 'Citations', 'Journal', 'Abstract', 'BibTeX']
433
  # Only include columns that exist
434
  available_cols = [col for col in column_order if col in df.columns]
435
  df = df[available_cols]
436
-
437
  summary = f"✅ Found **{len(all_papers)}** paper(s) matching your query"
438
  return df, all_papers, summary
439
-
440
  return pd.DataFrame(), [], "❌ No papers found"
441
 
442
  def extract_info(self, work):
@@ -454,12 +436,12 @@ class PaperSearchPro:
454
 
455
  # Get all authors - FULL LIST (no et al.)
456
  all_authors = []
457
-
458
  for authorship in work.get("authorships", []):
459
  # FIRST PRIORITY: Use raw_author_name (full name as published)
460
  raw_name = authorship.get("raw_author_name", "")
461
  display_name = authorship.get("author", {}).get("display_name", "")
462
-
463
  # Choose the best name
464
  if raw_name and len(raw_name) > 2:
465
  # Raw name is usually more complete (e.g., "Mamoru SHOJI" vs "M. Shoji")
@@ -468,18 +450,18 @@ class PaperSearchPro:
468
  author_name = display_name
469
  else:
470
  author_name = ""
471
-
472
  if author_name:
473
  all_authors.append(author_name)
474
-
475
  # Show ALL authors, no truncation
476
  authors_str = ", ".join(all_authors)
477
-
478
  # Get DOI for reference
479
  doi = work.get("doi", "")
480
  if doi:
481
  doi = doi.replace("https://doi.org/", "")
482
-
483
  # Generate BibTeX entry
484
  bibtex = self.generate_bibtex(work, all_authors)
485
 
@@ -496,33 +478,33 @@ class PaperSearchPro:
496
  "Relevance": 0,
497
  "Matched Keywords": ""
498
  }
499
-
500
  def generate_bibtex(self, work, authors):
501
  """Generate BibTeX entry for a paper"""
502
-
503
  # Create citation key
504
  first_author = authors[0].split()[-1] if authors else "Unknown"
505
  year = work.get("publication_year", "0000")
506
  title_words = work.get("title", "Untitled").split()[:3]
507
  title_short = "".join([w[0] for w in title_words if w]) if title_words else "Paper"
508
  citation_key = f"{first_author}{year}{title_short}"
509
-
510
  # Clean the citation key (remove special characters)
511
  citation_key = ''.join(c for c in citation_key if c.isalnum())
512
-
513
  # Get DOI or URL
514
  doi = work.get("doi", "")
515
  url = work.get("primary_location", {}).get("landing_page_url", "")
516
  if not url and work.get("open_access", {}).get("oa_url"):
517
  url = work.get("open_access", {}).get("oa_url")
518
-
519
  # Determine entry type (article, book, etc.)
520
  pub_type = "article"
521
  if work.get("type") == "book":
522
  pub_type = "book"
523
  elif work.get("type") == "book-chapter":
524
  pub_type = "incollection"
525
-
526
  # Build BibTeX string
527
  bibtex_lines = [
528
  f"@{pub_type}{{{citation_key},",
@@ -530,7 +512,7 @@ class PaperSearchPro:
530
  f" author = {{{' and '.join(authors)}}},",
531
  f" year = {{{work.get('publication_year', '0000')}}},"
532
  ]
533
-
534
  # Add journal/booktitle
535
  source = (work.get("primary_location", {}).get("source") or {})
536
  if pub_type == "article":
@@ -539,24 +521,24 @@ class PaperSearchPro:
539
  else:
540
  booktitle = source.get("display_name", "Unknown Publication")
541
  bibtex_lines.append(f" booktitle = {{{booktitle}}},")
542
-
543
  # Add volume, issue if available
544
  if work.get("biblio", {}).get("volume"):
545
  bibtex_lines.append(f" volume = {{{work['biblio']['volume']}}},")
546
  if work.get("biblio", {}).get("issue"):
547
  bibtex_lines.append(f" number = {{{work['biblio']['issue']}}},")
548
-
549
  # Add pages if available
550
  if work.get("biblio", {}).get("first_page") and work.get("biblio", {}).get("last_page"):
551
  pages = f"{work['biblio']['first_page']}--{work['biblio']['last_page']}"
552
  bibtex_lines.append(f" pages = {{{pages}}},")
553
-
554
  # Add DOI/URL
555
  if doi:
556
  bibtex_lines.append(f" doi = {{{doi}}},")
557
  elif url:
558
  bibtex_lines.append(f" url = {{{url}}},")
559
-
560
  # Add abstract if available
561
  if work.get("abstract_inverted_index"):
562
  # Rebuild abstract for BibTeX
@@ -568,10 +550,10 @@ class PaperSearchPro:
568
  abstract = " ".join([w[1] for w in words])
569
  if abstract:
570
  bibtex_lines.append(f" abstract = {{{abstract}}},")
571
-
572
  # Close the entry
573
  bibtex_lines.append("}")
574
-
575
  return "\n".join(bibtex_lines)
576
 
577
 
@@ -603,7 +585,7 @@ def create_interface():
603
  with gr.Column(elem_classes="white-card"):
604
 
605
  query = gr.Textbox(
606
- label="Search Topic",
607
  value="photoacoustic imaging",
608
  placeholder="Enter research topic or keywords..."
609
  )
@@ -615,7 +597,7 @@ def create_interface():
615
  value="blood, photoacoustics, imaging",
616
  placeholder="e.g., blood, photoacoustics, imaging (comma-separated)"
617
  )
618
-
619
  with gr.Column():
620
  authors = gr.Textbox(
621
  label="Filter by Authors (optional)",
@@ -627,7 +609,7 @@ def create_interface():
627
  # MAX PAPERS SLIDER WITH BLACK REGION COMMENT
628
  # ==========================
629
  max_papers = gr.Slider(1000, 50000, value=1000, step=100, label="Max Papers")
630
-
631
  # Add black region comment below slider
632
  gr.HTML("""
633
  <div class="slider-comment">
@@ -666,23 +648,23 @@ def create_interface():
666
  - **Exact Title** (e.g., "Photoacoustic imaging in biomedicine")
667
  - **Author** (find papers by a specific researcher)
668
  """)
669
-
670
  with gr.Row():
671
  specific_search_type = gr.Dropdown(
672
  label="Search by",
673
  choices=["DOI", "Exact Title", "Specific Author"],
674
  value="DOI"
675
  )
676
-
677
  specific_search_value = gr.Textbox(
678
  label="Enter value",
679
  placeholder="e.g., 10.1038/nature12373 or exact paper title or author name",
680
  scale=2
681
  )
682
-
683
  specific_search_btn = gr.Button("🔍 FIND PAPER", variant="primary")
684
  specific_summary = gr.Markdown("Ready")
685
-
686
  # Metrics section (common for both tabs)
687
  with gr.Row():
688
  total_display = gr.Markdown("**0**", elem_classes="metric-value")
@@ -714,7 +696,7 @@ def create_interface():
714
 
715
  with gr.Row():
716
  filename = gr.Textbox(
717
- label="Filename",
718
  value="papers_results",
719
  placeholder="Enter base filename without extension"
720
  )
@@ -745,13 +727,13 @@ def create_interface():
745
  df, papers, summary = searcher.search_specific_paper(search_type, search_value)
746
  if not papers:
747
  return df, papers, summary, "**0**", "**0.0**", "**N/A**"
748
-
749
  # Calculate metrics for display
750
  total = len(papers)
751
  avg_rel = 0
752
  years = [p["Year"] for p in papers if p["Year"] != "N/A"]
753
  year_range = f"{min(years)} - {max(years)}" if years else "N/A"
754
-
755
  return df, papers, summary, f"**{total}**", f"**{avg_rel:.2f}**", f"**{year_range}**"
756
  except Exception as e:
757
  empty_df = pd.DataFrame(columns=['Title', 'Authors', 'Year', 'Citations', 'Journal', 'Abstract', 'BibTeX'])
@@ -763,7 +745,7 @@ def create_interface():
763
  inputs=[query, keywords, authors, max_papers, year_from, year_to, open_access, sort_by, sort_order],
764
  outputs=[results, state, total_display, avg_display, year_display]
765
  )
766
-
767
  specific_search_btn.click(
768
  specific_search_wrapper,
769
  inputs=[specific_search_type, specific_search_value],
@@ -777,7 +759,7 @@ def create_interface():
777
 
778
  df = pd.DataFrame(papers)
779
  timestamp = datetime.now().strftime("%Y%m%d_%H%M%S")
780
-
781
  # Remove All Authors column from export if it exists
782
  if 'All Authors' in df.columns:
783
  df = df.drop(columns=['All Authors'])
@@ -805,7 +787,7 @@ def create_interface():
805
  f.write(f"Generated: {datetime.now().strftime('%Y-%m-%d %H:%M:%S')}\n")
806
  f.write(f"Total Papers: {len(df)}\n")
807
  f.write("="*80 + "\n\n")
808
-
809
  for i, row in df.iterrows():
810
  f.write(f"PAPER #{i+1}\n")
811
  f.write("-"*40 + "\n")
@@ -834,7 +816,7 @@ def create_interface():
834
  if __name__ == "__main__":
835
  demo = create_interface()
836
  demo.launch(
837
- inbrowser=True,
838
  height=1000,
839
  server_name="0.0.0.0", # Makes it accessible on network
840
  share=False # Set to True for temporary public link
 
136
  border-radius: 6px !important;
137
  }
138
 
139
+ /* ========================================= */
140
+ /* FORCE BUTTON TEXT TO ALWAYS BE WHITE */
141
+ /* ========================================= */
142
+
143
+ /* All buttons */
144
+ button,
145
+ .gr-button {
146
+ color: #ffffff !important; /* TEXT WHITE */
 
 
 
 
 
 
 
 
147
  }
148
 
149
+ /* Primary button */
150
+ button.variant-primary {
151
+ background-color: #2563eb !important; /* keep blue */
152
+ color: #ffffff !important; /* TEXT WHITE */
 
 
 
 
 
 
 
153
  }
154
 
155
+ /* Secondary button */
156
+ button.variant-secondary {
157
+ background-color: #6b7280 !important; /* keep gray */
158
+ color: #ffffff !important; /* TEXT WHITE */
 
 
159
  }
160
 
161
+ /* Keep text white even on hover */
162
+ button:hover {
163
  color: #ffffff !important;
 
164
  }
165
  /* ================================================= */
166
  /* METRIC LABEL BLACK BACKGROUND */
 
215
  filters.append(f"publication_year:<{int(year_to)+1}")
216
  if open_access:
217
  filters.append("open_access.is_oa:true")
218
+
219
  # Add author filter if provided
220
  if authors and authors.strip():
221
  # Clean and format author names for filtering
 
302
  # Sort by relevance score (our calculated score)
303
  filtered.sort(key=lambda x: x["Relevance"], reverse=True)
304
  all_papers = filtered[:max_papers]
305
+
306
  # ===============================
307
  # AUTHOR FILTERING (post-API)
308
  # ===============================
 
310
  # If we have author filter but no keyword hierarchy
311
  author_list = [a.strip().lower() for a in authors.split(",") if a.strip()]
312
  filtered = []
313
+
314
  for p in all_papers:
315
  all_authors_lower = p['All Authors'].lower()
316
  match_all = True
317
  matched_authors = []
318
+
319
  for author in author_list:
320
  if author in all_authors_lower:
321
  matched_authors.append(author)
322
  else:
323
  match_all = False
324
  break
325
+
326
  if match_all:
327
  p["Relevance"] = len(matched_authors)
328
  p["Matched Keywords"] = f"Authors: {', '.join(matched_authors)}"
329
  filtered.append(p)
330
+
331
  all_papers = filtered[:max_papers]
332
 
333
  total = len(all_papers)
 
336
  year_range = f"{min(years)} - {max(years)}" if years else "N/A"
337
 
338
  df = pd.DataFrame(all_papers)
339
+
340
  # Reorder columns to include BibTeX and remove All Authors from display
341
+ column_order = ['Title', 'Authors', 'Year', 'Citations', 'Journal', 'Abstract',
342
  'BibTeX', 'Relevance', 'Matched Keywords']
343
  df = df[column_order]
344
 
345
  return df, all_papers, total, avg_rel, year_range
346
+
347
  def search_specific_paper(self, search_type, search_value):
348
  """Search for a specific paper by title, author, or DOI"""
349
+
350
  all_papers = []
351
+
352
  if search_type == "DOI":
353
  # Clean DOI (remove URL if present)
354
  if "doi.org/" in search_value:
355
  search_value = search_value.split("doi.org/")[-1]
356
+
357
  # Direct lookup by DOI
358
  url = f"https://api.openalex.org/works/doi/{search_value}"
359
  try:
 
364
  all_papers.append(paper)
365
  except Exception as e:
366
  print(f"Error fetching DOI: {e}")
367
+
368
  elif search_type == "Exact Title":
369
  # Search by exact title
370
  params = {
 
376
  response = requests.get(self.base_url, params=params, timeout=15)
377
  data = response.json()
378
  results = data.get("results", [])
379
+
380
  for work in results:
381
  # Check for close title match
382
  title = work.get("title", "").lower()
 
386
  break # Take the first good match
387
  except Exception as e:
388
  print(f"Error searching title: {e}")
389
+
390
  elif search_type == "Specific Author":
391
  # Search for papers by a specific author
392
  params = {
 
399
  response = requests.get(self.base_url, params=params, timeout=15)
400
  data = response.json()
401
  results = data.get("results", [])
402
+
403
  for work in results[:20]: # Limit to 20 papers
404
  paper = self.extract_info(work)
405
  all_papers.append(paper)
406
  except Exception as e:
407
  print(f"Error searching author: {e}")
408
+
409
  if all_papers:
410
  for i, p in enumerate(all_papers):
411
  p['Rank'] = i + 1
412
+
413
  df = pd.DataFrame(all_papers)
414
  column_order = ['Title', 'Authors', 'Year', 'Citations', 'Journal', 'Abstract', 'BibTeX']
415
  # Only include columns that exist
416
  available_cols = [col for col in column_order if col in df.columns]
417
  df = df[available_cols]
418
+
419
  summary = f"✅ Found **{len(all_papers)}** paper(s) matching your query"
420
  return df, all_papers, summary
421
+
422
  return pd.DataFrame(), [], "❌ No papers found"
423
 
424
  def extract_info(self, work):
 
436
 
437
  # Get all authors - FULL LIST (no et al.)
438
  all_authors = []
439
+
440
  for authorship in work.get("authorships", []):
441
  # FIRST PRIORITY: Use raw_author_name (full name as published)
442
  raw_name = authorship.get("raw_author_name", "")
443
  display_name = authorship.get("author", {}).get("display_name", "")
444
+
445
  # Choose the best name
446
  if raw_name and len(raw_name) > 2:
447
  # Raw name is usually more complete (e.g., "Mamoru SHOJI" vs "M. Shoji")
 
450
  author_name = display_name
451
  else:
452
  author_name = ""
453
+
454
  if author_name:
455
  all_authors.append(author_name)
456
+
457
  # Show ALL authors, no truncation
458
  authors_str = ", ".join(all_authors)
459
+
460
  # Get DOI for reference
461
  doi = work.get("doi", "")
462
  if doi:
463
  doi = doi.replace("https://doi.org/", "")
464
+
465
  # Generate BibTeX entry
466
  bibtex = self.generate_bibtex(work, all_authors)
467
 
 
478
  "Relevance": 0,
479
  "Matched Keywords": ""
480
  }
481
+
482
  def generate_bibtex(self, work, authors):
483
  """Generate BibTeX entry for a paper"""
484
+
485
  # Create citation key
486
  first_author = authors[0].split()[-1] if authors else "Unknown"
487
  year = work.get("publication_year", "0000")
488
  title_words = work.get("title", "Untitled").split()[:3]
489
  title_short = "".join([w[0] for w in title_words if w]) if title_words else "Paper"
490
  citation_key = f"{first_author}{year}{title_short}"
491
+
492
  # Clean the citation key (remove special characters)
493
  citation_key = ''.join(c for c in citation_key if c.isalnum())
494
+
495
  # Get DOI or URL
496
  doi = work.get("doi", "")
497
  url = work.get("primary_location", {}).get("landing_page_url", "")
498
  if not url and work.get("open_access", {}).get("oa_url"):
499
  url = work.get("open_access", {}).get("oa_url")
500
+
501
  # Determine entry type (article, book, etc.)
502
  pub_type = "article"
503
  if work.get("type") == "book":
504
  pub_type = "book"
505
  elif work.get("type") == "book-chapter":
506
  pub_type = "incollection"
507
+
508
  # Build BibTeX string
509
  bibtex_lines = [
510
  f"@{pub_type}{{{citation_key},",
 
512
  f" author = {{{' and '.join(authors)}}},",
513
  f" year = {{{work.get('publication_year', '0000')}}},"
514
  ]
515
+
516
  # Add journal/booktitle
517
  source = (work.get("primary_location", {}).get("source") or {})
518
  if pub_type == "article":
 
521
  else:
522
  booktitle = source.get("display_name", "Unknown Publication")
523
  bibtex_lines.append(f" booktitle = {{{booktitle}}},")
524
+
525
  # Add volume, issue if available
526
  if work.get("biblio", {}).get("volume"):
527
  bibtex_lines.append(f" volume = {{{work['biblio']['volume']}}},")
528
  if work.get("biblio", {}).get("issue"):
529
  bibtex_lines.append(f" number = {{{work['biblio']['issue']}}},")
530
+
531
  # Add pages if available
532
  if work.get("biblio", {}).get("first_page") and work.get("biblio", {}).get("last_page"):
533
  pages = f"{work['biblio']['first_page']}--{work['biblio']['last_page']}"
534
  bibtex_lines.append(f" pages = {{{pages}}},")
535
+
536
  # Add DOI/URL
537
  if doi:
538
  bibtex_lines.append(f" doi = {{{doi}}},")
539
  elif url:
540
  bibtex_lines.append(f" url = {{{url}}},")
541
+
542
  # Add abstract if available
543
  if work.get("abstract_inverted_index"):
544
  # Rebuild abstract for BibTeX
 
550
  abstract = " ".join([w[1] for w in words])
551
  if abstract:
552
  bibtex_lines.append(f" abstract = {{{abstract}}},")
553
+
554
  # Close the entry
555
  bibtex_lines.append("}")
556
+
557
  return "\n".join(bibtex_lines)
558
 
559
 
 
585
  with gr.Column(elem_classes="white-card"):
586
 
587
  query = gr.Textbox(
588
+ label="Search Topic",
589
  value="photoacoustic imaging",
590
  placeholder="Enter research topic or keywords..."
591
  )
 
597
  value="blood, photoacoustics, imaging",
598
  placeholder="e.g., blood, photoacoustics, imaging (comma-separated)"
599
  )
600
+
601
  with gr.Column():
602
  authors = gr.Textbox(
603
  label="Filter by Authors (optional)",
 
609
  # MAX PAPERS SLIDER WITH BLACK REGION COMMENT
610
  # ==========================
611
  max_papers = gr.Slider(1000, 50000, value=1000, step=100, label="Max Papers")
612
+
613
  # Add black region comment below slider
614
  gr.HTML("""
615
  <div class="slider-comment">
 
648
  - **Exact Title** (e.g., "Photoacoustic imaging in biomedicine")
649
  - **Author** (find papers by a specific researcher)
650
  """)
651
+
652
  with gr.Row():
653
  specific_search_type = gr.Dropdown(
654
  label="Search by",
655
  choices=["DOI", "Exact Title", "Specific Author"],
656
  value="DOI"
657
  )
658
+
659
  specific_search_value = gr.Textbox(
660
  label="Enter value",
661
  placeholder="e.g., 10.1038/nature12373 or exact paper title or author name",
662
  scale=2
663
  )
664
+
665
  specific_search_btn = gr.Button("🔍 FIND PAPER", variant="primary")
666
  specific_summary = gr.Markdown("Ready")
667
+
668
  # Metrics section (common for both tabs)
669
  with gr.Row():
670
  total_display = gr.Markdown("**0**", elem_classes="metric-value")
 
696
 
697
  with gr.Row():
698
  filename = gr.Textbox(
699
+ label="Filename",
700
  value="papers_results",
701
  placeholder="Enter base filename without extension"
702
  )
 
727
  df, papers, summary = searcher.search_specific_paper(search_type, search_value)
728
  if not papers:
729
  return df, papers, summary, "**0**", "**0.0**", "**N/A**"
730
+
731
  # Calculate metrics for display
732
  total = len(papers)
733
  avg_rel = 0
734
  years = [p["Year"] for p in papers if p["Year"] != "N/A"]
735
  year_range = f"{min(years)} - {max(years)}" if years else "N/A"
736
+
737
  return df, papers, summary, f"**{total}**", f"**{avg_rel:.2f}**", f"**{year_range}**"
738
  except Exception as e:
739
  empty_df = pd.DataFrame(columns=['Title', 'Authors', 'Year', 'Citations', 'Journal', 'Abstract', 'BibTeX'])
 
745
  inputs=[query, keywords, authors, max_papers, year_from, year_to, open_access, sort_by, sort_order],
746
  outputs=[results, state, total_display, avg_display, year_display]
747
  )
748
+
749
  specific_search_btn.click(
750
  specific_search_wrapper,
751
  inputs=[specific_search_type, specific_search_value],
 
759
 
760
  df = pd.DataFrame(papers)
761
  timestamp = datetime.now().strftime("%Y%m%d_%H%M%S")
762
+
763
  # Remove All Authors column from export if it exists
764
  if 'All Authors' in df.columns:
765
  df = df.drop(columns=['All Authors'])
 
787
  f.write(f"Generated: {datetime.now().strftime('%Y-%m-%d %H:%M:%S')}\n")
788
  f.write(f"Total Papers: {len(df)}\n")
789
  f.write("="*80 + "\n\n")
790
+
791
  for i, row in df.iterrows():
792
  f.write(f"PAPER #{i+1}\n")
793
  f.write("-"*40 + "\n")
 
816
  if __name__ == "__main__":
817
  demo = create_interface()
818
  demo.launch(
819
+ inbrowser=True,
820
  height=1000,
821
  server_name="0.0.0.0", # Makes it accessible on network
822
  share=False # Set to True for temporary public link