Huggingface Paper Publisher
Hugging FaceOfficialPublished by Hugging Face
- Skill
- Tool integration
- Data and AI
- Apache-2.0
- Low risk
- Has scripts
AutoGineer summary
Written by AutoGineer from the skill’s own files, not by the author
The huggingface-paper-publisher skill provides a suite of tools for AI researchers and engineers to integrate their work with the Hugging Face Hub. It facilitates the entire lifecycle of a research paper, from generating formatted markdown articles using professional templates to indexing arXiv papers, linking them to specific models or datasets, and managing authorship claims. By automating metadata management and repository linking, this skill ensures that research is discoverable, properly cited, and well-integrated with technical artifacts.
What it does
- Indexes research papers on the Hugging Face Hub using arXiv IDs.
- Links papers to specific models and datasets via README metadata.
- Generates professional research articles using pre-defined markdown templates.
- Manages authorship verification and profile visibility for published papers.
- Provides utilities for citation generation and paper information retrieval.
- Converts markdown-based research papers into HTML formats.
When to use it
- When you need to link your published research to your models or datasets on Hugging Face.
- When you want to create a new research paper using standardized, modern markdown templates.
- When you need to claim authorship of your work on the Hugging Face platform.
- When you want to ensure your research is discoverable through the Hugging Face paper indexing system.
Advantages
- Streamlines the connection between research papers and technical artifacts.
- Supports multiple professional paper templates including modern and arXiv-style layouts.
- Automates the addition of required YAML metadata to model and dataset cards.
- Simplifies the authorship claim process for researchers.
- Enables batch processing for linking multiple papers to repositories.
Usage examples
- “Index my new paper with arXiv ID 2301.12345 on Hugging Face.”
- The skill triggers the indexing process, making the paper discoverable at the corresponding Hugging Face paper page.
- “Link my model username/model-name to the paper 2301.12345.”
- The script updates the model's README with the correct arXiv metadata and citation, enabling automatic tagging on the Hub.
- “Create a new research paper using the modern template.”
- The tool generates a structured markdown file with the specified title and sections, ready for content population.
- “Claim authorship for paper 2301.12345 using my institutional email.”
- The skill initiates the verification workflow, allowing the user to link the paper to their public profile.
Install
Download the skill as a ZIP:
https://autogineer.com/agent-skills/huggingface/huggingface-paper-publisher/downloadUnzip it into the cross-client skills folder of your project:
mkdir -p .agents/skills && unzip huggingface-paper-publisher.zip -d .agents/skills
Documentation by Hugging Face
Overview
This skill provides comprehensive tools for AI engineers and researchers to publish, manage, and link research papers on the Hugging Face Hub. It streamlines the workflow from paper creation to publication, including integration with arXiv, model/dataset linking, and authorship management.
Integration with HF Ecosystem
Paper Pages: Index and discover papers on Hugging Face Hub
arXiv Integration: Automatic paper indexing from arXiv IDs
Model/Dataset Linking: Connect papers to relevant artifacts through metadata
Authorship Verification: Claim and verify paper authorship
Research Article Template: Generate professional, modern scientific papers
Version
1.0.0
Dependencies
The included script uses PEP 723 inline dependencies. Prefer uv run over
manual environment setup.
huggingface_hub>=0.26.0
pyyaml>=6.0.3
requests>=2.32.5
markdown>=3.5.0
python-dotenv>=1.2.1
Core Capabilities
1. Paper Page Management
Index Papers: Add papers to Hugging Face from arXiv
Claim Authorship: Verify and claim authorship on published papers
Manage Visibility: Control which papers appear on your profile
Paper Discovery: Find and explore papers in the HF ecosystem
2. Link Papers to Artifacts
Model Cards: Add paper citations to model metadata
Dataset Cards: Link papers to datasets via README
Automatic Tagging: Hub auto-generates arxiv:<PAPER_ID> tags
Citation Management: Maintain proper attribution and references
3. Research Article Creation
Markdown Templates: Generate professional paper formatting
Modern Design: Clean, readable research article layouts
Dynamic TOC: Automatic table of contents generation
Section Structure: Standard scientific paper organization
LaTeX Math: Support for equations and technical notation
4. Metadata Management
YAML Frontmatter: Proper model/dataset card metadata
Citation Tracking: Maintain paper references across repositories
Version Control: Track paper updates and revisions
Multi-Paper Support: Link multiple papers to single artifacts
Usage Instructions
The skill includes Python scripts in scripts/ for paper publishing operations.
Prerequisites
Run scripts with
uv run(dependencies are resolved from the script header)Set
HF_TOKENenvironment variable with Write-access token
All paths are relative to the directory containing this SKILL.md file. Before running any script, first
cdto that directory or use the full path.
Method 1: Index Paper from arXiv
Add a paper to Hugging Face Paper Pages from arXiv.
Basic Usage:
uv run scripts/paper_manager.py index \
--arxiv-id "2301.12345"Check If Paper Exists:
uv run scripts/paper_manager.py check \
--arxiv-id "2301.12345"Direct URL Access:
You can also visit https://huggingface.co/papers/{arxiv-id} directly to index a paper.
Method 2: Link Paper to Model/Dataset
Add paper references to model or dataset README with proper YAML metadata.
Add to Model Card:
uv run scripts/paper_manager.py link \
--repo-id "username/model-name" \
--repo-type "model" \
--arxiv-id "2301.12345"Add to Dataset Card:
uv run scripts/paper_manager.py link \
--repo-id "username/dataset-name" \
--repo-type "dataset" \
--arxiv-id "2301.12345"Add Multiple Papers:
uv run scripts/paper_manager.py link \
--repo-id "username/model-name" \
--repo-type "model" \
--arxiv-ids "2301.12345,2302.67890,2303.11111"With Custom Citation:
uv run scripts/paper_manager.py link \
--repo-id "username/model-name" \
--repo-type "model" \
--arxiv-id "2301.12345" \
--citation "$(cat citation.txt)"How Linking Works
When you add an arXiv paper link to a model or dataset README:
The Hub extracts the arXiv ID from the link
A tag
arxiv:<PAPER_ID>is automatically added to the repositoryUsers can click the tag to view the Paper Page
The Paper Page shows all models/datasets citing this paper
Papers are discoverable through filters and search
Method 3: Claim Authorship
Verify your authorship on papers published on Hugging Face.
Start Claim Process:
uv run scripts/paper_manager.py claim \
--arxiv-id "2301.12345" \
--email "[email protected]"Manual Process:
Navigate to your paper's page:
https://huggingface.co/papers/{arxiv-id}Find your name in the author list
Click your name and select "Claim authorship"
Wait for admin team verification
Check Authorship Status:
uv run scripts/paper_manager.py check-authorship \
--arxiv-id "2301.12345"Method 4: Manage Paper Visibility
Control which verified papers appear on your public profile.
List Your Papers:
uv run scripts/paper_manager.py list-my-papersToggle Visibility:
uv run scripts/paper_manager.py toggle-visibility \
--arxiv-id "2301.12345" \
--show trueManage in Settings: Navigate to your account settings → Papers section to toggle "Show on profile" for each paper.
Method 5: Create Research Article
Generate a professional markdown-based research paper using modern templates.
Create from Template:
uv run scripts/paper_manager.py create \
--template "standard" \
--title "Your Paper Title" \
--output "paper.md"Available Templates:
standard- Traditional scientific paper structuremodern- Clean, web-friendly format inspired by Distillarxiv- arXiv-style formattingml-report- Machine learning experiment report
Generate Complete Paper:
uv run scripts/paper_manager.py create \
--template "modern" \
--title "Fine-Tuning Large Language Models with LoRA" \
--authors "Jane Doe, John Smith" \
--abstract "$(cat abstract.txt)" \
--output "paper.md"Convert to HTML:
uv run scripts/paper_manager.py convert \
--input "paper.md" \
--output "paper.html" \
--style "modern"Paper Template Structure
Standard Research Paper Sections:
---
title: Your Paper Title
authors: Jane Doe, John Smith
affiliations: University X, Lab Y
date: 2025-01-15
arxiv: 2301.12345
tags: [machine-learning, nlp, fine-tuning]
---
# Abstract
Brief summary of the paper...
# 1. Introduction
Background and motivation...
# 2. Related Work
Previous research and context...
# 3. Methodology
Approach and implementation...
# 4. Experiments
Setup, datasets, and procedures...
# 5. Results
Findings and analysis...
# 6. Discussion
Interpretation and implications...
# 7. Conclusion
Summary and future work...
# ReferencesModern Template Features:
Dynamic table of contents
Responsive design for web viewing
Code syntax highlighting
Interactive figures and charts
Math equation rendering (LaTeX)
Citation management
Author affiliation linking
Commands Reference
Index Paper:
uv run scripts/paper_manager.py index --arxiv-id "2301.12345"Link to Repository:
uv run scripts/paper_manager.py link \
--repo-id "username/repo-name" \
--repo-type "model|dataset|space" \
--arxiv-id "2301.12345" \
[--citation "Full citation text"] \
[--create-pr]Claim Authorship:
uv run scripts/paper_manager.py claim \
--arxiv-id "2301.12345" \
--email "your.email@edu"Manage Visibility:
uv run scripts/paper_manager.py toggle-visibility \
--arxiv-id "2301.12345" \
--show true|falseCreate Research Article:
uv run scripts/paper_manager.py create \
--template "standard|modern|arxiv|ml-report" \
--title "Paper Title" \
[--authors "Author1, Author2"] \
[--abstract "Abstract text"] \
[--output "filename.md"]Convert Markdown to HTML:
uv run scripts/paper_manager.py convert \
--input "paper.md" \
--output "paper.html" \
[--style "modern|classic"]Check Paper Status:
uv run scripts/paper_manager.py check --arxiv-id "2301.12345"List Your Papers:
uv run scripts/paper_manager.py list-my-papersSearch Papers:
uv run scripts/paper_manager.py search --query "transformer attention"YAML Metadata Format
When linking papers to models or datasets, proper YAML frontmatter is required:
Model Card Example:
---
language:
- en
license: apache-2.0
tags:
- text-generation
- transformers
- llm
library_name: transformers
---
# Model Name
This model is based on the approach described in [Our Paper](https://arxiv.org/abs/2301.12345).
## Citation
```bibtex
@article{doe2023paper,
title={Your Paper Title},
author={Doe, Jane and Smith, John},
journal={arXiv preprint arXiv:2301.12345},
year={2023}
}
**Dataset Card Example:**
```yaml
---
language:
- en
license: cc-by-4.0
task_categories:
- text-generation
- question-answering
size_categories:
- 10K<n<100K
---
# Dataset Name
Dataset introduced in [Our Paper](https://arxiv.org/abs/2301.12345).
For more details, see the [paper page](https://huggingface.co/papers/2301.12345).The Hub automatically extracts arXiv IDs from these links and creates arxiv:2301.12345 tags.
Integration Examples
Workflow 1: Publish New Research
# 1. Create research article
uv run scripts/paper_manager.py create \
--template "modern" \
--title "Novel Fine-Tuning Approach" \
--output "paper.md"
# 2. Edit paper.md with your content
# 3. Submit to arXiv (external process)
# Upload to arxiv.org, get arXiv ID
# 4. Index on Hugging Face
uv run scripts/paper_manager.py index --arxiv-id "2301.12345"
# 5. Link to your model
uv run scripts/paper_manager.py link \
--repo-id "your-username/your-model" \
--repo-type "model" \
--arxiv-id "2301.12345"
# 6. Claim authorship
uv run scripts/paper_manager.py claim \
--arxiv-id "2301.12345" \
--email "your.email@edu"Workflow 2: Link Existing Paper
# 1. Check if paper exists
uv run scripts/paper_manager.py check --arxiv-id "2301.12345"
# 2. Index if needed
uv run scripts/paper_manager.py index --arxiv-id "2301.12345"
# 3. Link to multiple repositories
uv run scripts/paper_manager.py link \
--repo-id "username/model-v1" \
--repo-type "model" \
--arxiv-id "2301.12345"
uv run scripts/paper_manager.py link \
--repo-id "username/training-data" \
--repo-type "dataset" \
--arxiv-id "2301.12345"
uv run scripts/paper_manager.py link \
--repo-id "username/demo-space" \
--repo-type "space" \
--arxiv-id "2301.12345"Workflow 3: Update Model with Paper Reference
# 1. Get current README
hf download username/model-name README.md
# 2. Add paper link
uv run scripts/paper_manager.py link \
--repo-id "username/model-name" \
--repo-type "model" \
--arxiv-id "2301.12345" \
--citation "Full citation for the paper"
# The script will:
# - Add YAML metadata if missing
# - Insert arXiv link in README
# - Add formatted citation
# - Preserve existing contentBest Practices
Paper Indexing
Index papers as soon as they're published on arXiv
Include full citation information in model/dataset cards
Use consistent paper references across related repositories
Metadata Management
Add YAML frontmatter to all model/dataset cards
Include proper licensing information
Tag with relevant task categories and domains
Authorship
Claim authorship on papers where you're listed as author
Use institutional email addresses for verification
Keep paper visibility settings updated
Repository Linking
Link papers to all relevant models, datasets, and Spaces
Include paper context in README descriptions
Add BibTeX citations for easy reference
Research Articles
Use templates consistently within projects
Include code and data links in papers
Generate web-friendly HTML versions for sharing
Advanced Usage
Batch Link Papers:
# Link multiple papers to one repository
for arxiv_id in "2301.12345" "2302.67890" "2303.11111"; do
uv run scripts/paper_manager.py link \
--repo-id "username/model-name" \
--repo-type "model" \
--arxiv-id "$arxiv_id"
doneExtract Paper Info:
# Get paper metadata from arXiv
uv run scripts/paper_manager.py info \
--arxiv-id "2301.12345" \
--format "json"Generate Citation:
# Create BibTeX citation
uv run scripts/paper_manager.py citation \
--arxiv-id "2301.12345" \
--format "bibtex"Validate Links:
# Check all paper links in a repository
uv run scripts/paper_manager.py validate \
--repo-id "username/model-name" \
--repo-type "model"Error Handling
Paper Not Found: arXiv ID doesn't exist or isn't indexed yet
Permission Denied: HF_TOKEN lacks write access to repository
Invalid YAML: Malformed metadata in README frontmatter
Authorship Failed: Email doesn't match paper author records
Already Claimed: Another user has claimed authorship
Rate Limiting: Too many API requests in short time
Troubleshooting
Issue: "Paper not found on Hugging Face"
Solution: Visit
hf.co/papers/{arxiv-id}to trigger indexing
Issue: "Authorship claim not verified"
Solution: Wait for admin review or contact HF support with proof
Issue: "arXiv tag not appearing"
Solution: Ensure README includes proper arXiv URL format
Issue: "Cannot link to repository"
Solution: Verify HF_TOKEN has write permissions
Issue: "Template rendering errors"
Solution: Check markdown syntax and YAML frontmatter format
Resources and References
Hugging Face Paper Pages: hf.co/papers
Model Cards Guide: hf.co/docs/hub/model-cards
Dataset Cards Guide: hf.co/docs/hub/datasets-cards
Research Article Template: tfrere/research-article-template
arXiv Format Guide: arxiv.org/help/submit
Integration with tfrere's Research Template
This skill complements tfrere's research article template by providing:
Automated paper indexing workflows
Repository linking capabilities
Metadata management tools
Citation generation utilities
You can use tfrere's template for writing, then use this skill to publish and link the paper on Hugging Face Hub.
Common Patterns
Pattern 1: New Paper Publication
# Write → Publish → Index → Link
uv run scripts/paper_manager.py create --template modern --output paper.md
# (Submit to arXiv)
uv run scripts/paper_manager.py index --arxiv-id "2301.12345"
uv run scripts/paper_manager.py link --repo-id "user/model" --arxiv-id "2301.12345"Pattern 2: Existing Paper Discovery
# Search → Check → Link
uv run scripts/paper_manager.py search --query "transformers"
uv run scripts/paper_manager.py check --arxiv-id "2301.12345"
uv run scripts/paper_manager.py link --repo-id "user/model" --arxiv-id "2301.12345"Pattern 3: Author Portfolio Management
# Claim → Verify → Organize
uv run scripts/paper_manager.py claim --arxiv-id "2301.12345"
uv run scripts/paper_manager.py list-my-papers
uv run scripts/paper_manager.py toggle-visibility --arxiv-id "2301.12345" --show trueAPI Integration
Python Script Example:
from scripts.paper_manager import PaperManager
pm = PaperManager(hf_token="your_token")
# Index paper
pm.index_paper("2301.12345")
# Link to model
pm.link_paper(
repo_id="username/model",
repo_type="model",
arxiv_id="2301.12345",
citation="Full citation text"
)
# Check status
status = pm.check_paper("2301.12345")
print(status)Future Enhancements
Planned features for future versions:
Support for non-arXiv papers (conference proceedings, journals)
Automatic citation formatting from DOI
Paper comparison and versioning tools
Collaborative paper writing features
Integration with LaTeX workflows
Automated figure and table extraction
Paper metrics and impact tracking
Files
- ATTRIBUTION.mdAdded by AutoGineer898 B
- LICENSELicence file added by AutoGineer11.1 KiB
- SKILL.md16.3 KiB
- examples/example_usage.md8.3 KiB
- references/quick_reference.md4.4 KiB
- scripts/paper_manager.pyScript21.4 KiB
- templates/arxiv.md7.1 KiB
- templates/ml-report.md6.7 KiB
- templates/modern.md6.3 KiB
- templates/standard.md3.1 KiB
scripts/paper_manager.py
#!/usr/bin/env -S uv run
# /// script
# requires-python = ">=3.10"
# dependencies = [
# "huggingface_hub",
# "pyyaml",
# "requests",
# "python-dotenv",
# ]
# ///
"""
Paper Manager for Hugging Face Hub
Manages paper indexing, linking, authorship, and article creation.
"""
import argparse
import os
import sys
import re
import json
from pathlib import Path
from typing import Optional, List, Dict, Any
from datetime import datetime
try:
from huggingface_hub import HfApi, hf_hub_download, get_token
import yaml
import requests
from dotenv import load_dotenv
except ImportError as e:
print(f"Error: Missing required dependency: {e}")
print("Tip: run this script with `uv run scripts/paper_manager.py ...`.")
sys.exit(1)
# Load environment variables
load_dotenv()
class PaperManager:
"""Manages paper publishing operations on Hugging Face Hub."""
def __init__(self, hf_token: Optional[str] = None):
"""Initialize Paper Manager with HF token."""
self.token = hf_token or os.getenv("HF_TOKEN") or get_token()
if not self.token:
print("Warning: No HF_TOKEN found. Some operations will fail.")
self.api = HfApi(token=self.token)
def index_paper(self, arxiv_id: str) -> Dict[str, Any]:
"""
Index a paper on Hugging Face from arXiv.
Args:
arxiv_id: arXiv identifier (e.g., "2301.12345")
Returns:
dict: Status information
"""
# Clean and validate arXiv ID
try:
arxiv_id = self._clean_arxiv_id(arxiv_id)
except ValueError as e:
print(f"Error: {e}")
return {"status": "error", "message": str(e)}
print(f"Indexing paper {arxiv_id} on Hugging Face...")
# Check if paper exists
paper_url = f"https://huggingface.co/papers/{arxiv_id}"
try:
response = requests.get(paper_url, timeout=10)
if response.status_code == 200:
print(f"✓ Paper already indexed at {paper_url}")
return {"status": "exists", "url": paper_url}
else:
print(f"Paper not indexed. Visit {paper_url} to trigger indexing.")
print("The paper will be automatically indexed when you first visit the URL.")
return {"status": "not_indexed", "url": paper_url, "action": "visit_url"}
except requests.RequestException as e:
print(f"Error checking paper status: {e}")
return {"status": "error", "message": str(e)}
def check_paper(self, arxiv_id: str) -> Dict[str, Any]:
"""
Check if a paper exists on Hugging Face.
Args:
arxiv_id: arXiv identifier
Returns:
dict: Paper status and metadata
"""
try:
arxiv_id = self._clean_arxiv_id(arxiv_id)
except ValueError as e:
return {"exists": False, "error": str(e)}
paper_url = f"https://huggingface.co/papers/{arxiv_id}"
try:
response = requests.get(paper_url, timeout=10)
if response.status_code == 200:
return {
"exists": True,
"url": paper_url,
"arxiv_id": arxiv_id,
"arxiv_url": f"https://arxiv.org/abs/{arxiv_id}"
}
else:
return {
"exists": False,
"arxiv_id": arxiv_id,
"index_url": paper_url,
"message": f"Visit {paper_url} to index this paper"
}
except requests.RequestException as e:
return {"exists": False, "error": str(e)}
def link_paper_to_repo(
self,
repo_id: str,
arxiv_id: str,
repo_type: str = "model",
citation: Optional[str] = None,
create_pr: bool = False
) -> Dict[str, Any]:
"""
Link a paper to a model/dataset/space repository.
Args:
repo_id: Repository identifier (e.g., "username/repo-name")
arxiv_id: arXiv identifier
repo_type: Type of repository ("model", "dataset", or "space")
citation: Optional full citation text
create_pr: Create a PR instead of direct commit
Returns:
dict: Operation status
"""
try:
arxiv_id = self._clean_arxiv_id(arxiv_id)
except ValueError as e:
print(f"Error: {e}")
return {"status": "error", "message": str(e)}
print(f"Linking paper {arxiv_id} to {repo_type} {repo_id}...")
try:
# Download current README
readme_path = hf_hub_download(
repo_id=repo_id,
filename="README.md",
repo_type=repo_type,
token=self.token
)
with open(readme_path, 'r', encoding='utf-8') as f:
content = f.read()
# Parse or create YAML frontmatter
updated_content = self._add_paper_to_readme(content, arxiv_id, citation)
# Upload updated README
commit_message = f"Add paper reference: arXiv:{arxiv_id}"
if create_pr:
# Create PR (not implemented in basic version)
print("PR creation not yet implemented. Committing directly.")
self.api.upload_file(
path_or_fileobj=updated_content.encode('utf-8'),
path_in_repo="README.md",
repo_id=repo_id,
repo_type=repo_type,
commit_message=commit_message,
token=self.token
)
paper_url = f"https://huggingface.co/papers/{arxiv_id}"
repo_url = f"https://huggingface.co/{repo_id}"
print(f"✓ Successfully linked paper to repository")
print(f" Paper: {paper_url}")
print(f" Repo: {repo_url}")
return {
"status": "success",
"paper_url": paper_url,
"repo_url": repo_url,
"arxiv_id": arxiv_id
}
except Exception as e:
print(f"Error linking paper: {e}")
return {"status": "error", "message": str(e)}
def _add_paper_to_readme(
self,
content: str,
arxiv_id: str,
citation: Optional[str] = None
) -> str:
"""
Add paper reference to README content.
Args:
content: Current README content
arxiv_id: arXiv identifier
citation: Optional citation text
Returns:
str: Updated README content
"""
arxiv_url = f"https://arxiv.org/abs/{arxiv_id}"
hf_paper_url = f"https://huggingface.co/papers/{arxiv_id}"
# Check if YAML frontmatter exists
yaml_pattern = r'^---\s*\n(.*?)\n---\s*\n'
match = re.match(yaml_pattern, content, re.DOTALL)
if match:
# YAML exists, check if paper already referenced
if arxiv_id in content:
print(f"Paper {arxiv_id} already referenced in README")
return content
# Add to existing content (after YAML)
yaml_end = match.end()
before = content[:yaml_end]
after = content[yaml_end:]
else:
# No YAML, add minimal frontmatter
yaml_content = "---\n---\n\n"
before = yaml_content
after = content
# Add paper reference section with boundary markers
paper_section = "\n<!-- paper-manager:start -->\n"
paper_section += f"## Paper\n\n"
paper_section += f"This {'model' if 'model' in content.lower() else 'work'} is based on research presented in:\n\n"
paper_section += f"**[View on arXiv]({arxiv_url})** | "
paper_section += f"**[View on Hugging Face]({hf_paper_url})**\n\n"
if citation:
safe_citation = self._sanitize_text(citation)
paper_section += f"### Citation\n\n```bibtex\n{safe_citation}\n```\n\n"
paper_section += "<!-- paper-manager:end -->\n"
# Insert after YAML, before main content
updated_content = before + paper_section + after
return updated_content
def create_research_article(
self,
template: str,
title: str,
output: str,
authors: Optional[str] = None,
abstract: Optional[str] = None
) -> Dict[str, Any]:
"""
Create a research article from template.
Args:
template: Template name ("standard", "modern", "arxiv", "ml-report")
title: Paper title
output: Output filename
authors: Comma-separated author names
abstract: Abstract text
Returns:
dict: Creation status
"""
print(f"Creating research article with '{template}' template...")
# Load template
template_dir = Path(__file__).parent.parent / "templates"
template_file = template_dir / f"{template}.md"
if not template_file.exists():
return {
"status": "error",
"message": f"Template '{template}' not found at {template_file}"
}
with open(template_file, 'r', encoding='utf-8') as f:
template_content = f.read()
# Prepare safe values for different contexts
date_str = datetime.now().strftime("%Y-%m-%d")
safe_title_body = self._sanitize_text(title)
authors_val = authors if authors else "Your Name"
safe_authors_body = self._sanitize_text(authors_val)
abstract_val = abstract if abstract else "Abstract to be written..."
safe_abstract_body = self._sanitize_text(abstract_val)
# Split frontmatter from body for context-aware escaping
fm_pattern = r'^(---\s*\n)(.*?\n)(---\s*\n)'
fm_match = re.match(fm_pattern, template_content, re.DOTALL)
if fm_match:
fm_open, fm_body, fm_close = fm_match.group(1), fm_match.group(2), fm_match.group(3)
body = template_content[fm_match.end():]
# YAML-escape values in frontmatter
fm_body = fm_body.replace("{{TITLE}}", self._escape_yaml_value(title))
fm_body = fm_body.replace("{{AUTHORS}}", self._escape_yaml_value(authors_val))
fm_body = fm_body.replace("{{DATE}}", date_str)
# Sanitize values in body
body = body.replace("{{TITLE}}", safe_title_body)
body = body.replace("{{AUTHORS}}", safe_authors_body)
body = body.replace("{{ABSTRACT}}", safe_abstract_body)
body = body.replace("{{DATE}}", date_str)
content = fm_open + fm_body + fm_close + body
else:
# No frontmatter — sanitize everything
content = template_content.replace("{{TITLE}}", safe_title_body)
content = content.replace("{{DATE}}", date_str)
content = content.replace("{{AUTHORS}}", safe_authors_body)
content = content.replace("{{ABSTRACT}}", safe_abstract_body)
# Write output
with open(output, 'w', encoding='utf-8') as f:
f.write(content)
print(f"✓ Research article created at {output}")
return {
"status": "success",
"output": output,
"template": template
}
def get_arxiv_info(self, arxiv_id: str) -> Dict[str, Any]:
"""
Fetch paper information from arXiv API.
Args:
arxiv_id: arXiv identifier
Returns:
dict: Paper metadata
"""
try:
arxiv_id = self._clean_arxiv_id(arxiv_id)
except ValueError as e:
return {"error": str(e)}
api_url = f"https://export.arxiv.org/api/query?id_list={arxiv_id}"
try:
response = requests.get(api_url, timeout=10)
response.raise_for_status()
# Parse XML response (simplified)
content = response.text
# Extract basic info with regex (proper XML parsing would be better)
title_match = re.search(r'<title>(.*?)</title>', content, re.DOTALL)
authors_matches = re.findall(r'<name>(.*?)</name>', content)
summary_match = re.search(r'<summary>(.*?)</summary>', content, re.DOTALL)
# Sanitize all text extracted from the external API
raw_title = title_match.group(1).strip() if title_match else None
raw_authors = authors_matches[1:] if len(authors_matches) > 1 else []
raw_abstract = summary_match.group(1).strip() if summary_match else None
return {
"arxiv_id": arxiv_id,
"title": self._sanitize_text(raw_title) if raw_title else None,
"authors": [self._sanitize_text(a) for a in raw_authors],
"abstract": self._sanitize_text(raw_abstract) if raw_abstract else None,
"arxiv_url": f"https://arxiv.org/abs/{arxiv_id}",
"pdf_url": f"https://arxiv.org/pdf/{arxiv_id}.pdf"
}
except Exception as e:
return {"error": str(e)}
def generate_citation(
self,
arxiv_id: str,
format: str = "bibtex"
) -> str:
"""
Generate citation for a paper.
Args:
arxiv_id: arXiv identifier
format: Citation format ("bibtex", "apa", "mla")
Returns:
str: Formatted citation
"""
try:
arxiv_id = self._clean_arxiv_id(arxiv_id)
except ValueError as e:
return f"Error: {e}"
info = self.get_arxiv_info(arxiv_id)
if "error" in info:
return f"Error fetching paper info: {info['error']}"
if format == "bibtex":
# Generate BibTeX citation
key = f"arxiv{arxiv_id.replace('.', '_')}"
raw_authors = " and ".join(info.get("authors", ["Unknown"]))
raw_title = info.get("title", "Untitled")
year = arxiv_id.split(".")[0][:2] # Extract year from ID (simplified)
year = f"20{year}" if int(year) < 50 else f"19{year}"
# Escape BibTeX structural characters in untrusted values
safe_title = raw_title.replace('{', r'\{').replace('}', r'\}')
safe_authors = raw_authors.replace('{', r'\{').replace('}', r'\}')
citation = f"""@article{{{key},
title={{{safe_title}}},
author={{{safe_authors}}},
journal={{arXiv preprint arXiv:{arxiv_id}}},
year={{{year}}}
}}"""
return citation
return f"Format '{format}' not yet implemented"
# Patterns for valid arXiv IDs
_ARXIV_ID_MODERN = re.compile(r'^\d{4}\.\d{4,5}(v\d+)?$')
_ARXIV_ID_LEGACY = re.compile(r'^[a-zA-Z\-]+/\d{7}(v\d+)?$')
@staticmethod
def _clean_arxiv_id(arxiv_id: str) -> str:
"""Clean, normalize, and validate arXiv ID.
Raises:
ValueError: If the cleaned ID does not match a valid arXiv format.
"""
# Remove common prefixes and whitespace
arxiv_id = arxiv_id.strip()
arxiv_id = re.sub(r'^(arxiv:|arXiv:)', '', arxiv_id, flags=re.IGNORECASE)
arxiv_id = re.sub(r'https?://arxiv\.org/(abs|pdf)/', '', arxiv_id)
arxiv_id = arxiv_id.replace('.pdf', '')
# Validate format
if not (PaperManager._ARXIV_ID_MODERN.match(arxiv_id)
or PaperManager._ARXIV_ID_LEGACY.match(arxiv_id)):
raise ValueError(
f"Invalid arXiv ID: {arxiv_id!r}. "
"Expected format: YYMM.NNNNN[vN] or category/YYMMNNN[vN]"
)
return arxiv_id
@staticmethod
def _escape_yaml_value(value: str) -> str:
"""Escape a string for safe use as a YAML scalar value.
Wraps in double quotes and escapes internal quotes and backslashes
to prevent YAML injection via crafted titles/authors.
"""
value = value.replace('\\', '\\\\').replace('"', '\\"')
return f'"{value}"'
@staticmethod
def _sanitize_text(text: str) -> str:
"""Sanitize untrusted text for safe inclusion in Markdown/YAML output.
Normalizes whitespace, strips control characters, and neutralizes
markdown code-fence breakout and YAML document delimiters.
"""
# Remove control characters (keep newlines and tabs)
text = re.sub(r'[\x00-\x08\x0b\x0c\x0e-\x1f\x7f]', '', text)
# Normalize whitespace runs (collapse multiple spaces/tabs, preserve single newlines)
text = re.sub(r'[^\S\n]+', ' ', text)
text = re.sub(r'\n{3,}', '\n\n', text)
# Neutralize markdown code fence breakout
text = text.replace('```', r'\`\`\`')
# Neutralize YAML document delimiters at line start
text = re.sub(r'^---', r'\\---', text, flags=re.MULTILINE)
return text.strip()
def main():
"""Main CLI entry point."""
parser = argparse.ArgumentParser(
description="Paper Manager for Hugging Face Hub",
formatter_class=argparse.RawDescriptionHelpFormatter
)
subparsers = parser.add_subparsers(dest="command", help="Command to execute")
# Index command
index_parser = subparsers.add_parser("index", help="Index a paper from arXiv")
index_parser.add_argument("--arxiv-id", required=True, help="arXiv paper ID")
# Check command
check_parser = subparsers.add_parser("check", help="Check if paper exists")
check_parser.add_argument("--arxiv-id", required=True, help="arXiv paper ID")
# Link command
link_parser = subparsers.add_parser("link", help="Link paper to repository")
link_parser.add_argument("--repo-id", required=True, help="Repository ID")
link_parser.add_argument("--repo-type", default="model", choices=["model", "dataset", "space"])
link_parser.add_argument("--arxiv-id", help="Single arXiv ID")
link_parser.add_argument("--arxiv-ids", help="Comma-separated arXiv IDs")
link_parser.add_argument("--citation", help="Full citation text")
link_parser.add_argument("--create-pr", action="store_true", help="Create PR instead of direct commit")
# Create command
create_parser = subparsers.add_parser("create", help="Create research article")
create_parser.add_argument("--template", required=True, help="Template name")
create_parser.add_argument("--title", required=True, help="Paper title")
create_parser.add_argument("--output", required=True, help="Output filename")
create_parser.add_argument("--authors", help="Comma-separated authors")
create_parser.add_argument("--abstract", help="Abstract text")
# Info command
info_parser = subparsers.add_parser("info", help="Get paper information")
info_parser.add_argument("--arxiv-id", required=True, help="arXiv paper ID")
info_parser.add_argument("--format", default="json", choices=["json", "text"])
# Citation command
citation_parser = subparsers.add_parser("citation", help="Generate citation")
citation_parser.add_argument("--arxiv-id", required=True, help="arXiv paper ID")
citation_parser.add_argument("--format", default="bibtex", choices=["bibtex", "apa", "mla"])
# Search command
search_parser = subparsers.add_parser("search", help="Search papers")
search_parser.add_argument("--query", required=True, help="Search query")
args = parser.parse_args()
if not args.command:
parser.print_help()
sys.exit(1)
# Initialize manager
manager = PaperManager()
# Execute command
if args.command == "index":
result = manager.index_paper(args.arxiv_id)
print(json.dumps(result, indent=2))
elif args.command == "check":
result = manager.check_paper(args.arxiv_id)
print(json.dumps(result, indent=2))
elif args.command == "link":
arxiv_ids = []
if args.arxiv_id:
arxiv_ids.append(args.arxiv_id)
if args.arxiv_ids:
arxiv_ids.extend([id.strip() for id in args.arxiv_ids.split(",")])
if not arxiv_ids:
print("Error: Must provide --arxiv-id or --arxiv-ids")
sys.exit(1)
for arxiv_id in arxiv_ids:
result = manager.link_paper_to_repo(
repo_id=args.repo_id,
arxiv_id=arxiv_id,
repo_type=args.repo_type,
citation=args.citation,
create_pr=args.create_pr
)
print(json.dumps(result, indent=2))
elif args.command == "create":
result = manager.create_research_article(
template=args.template,
title=args.title,
output=args.output,
authors=args.authors,
abstract=args.abstract
)
print(json.dumps(result, indent=2))
elif args.command == "info":
result = manager.get_arxiv_info(args.arxiv_id)
if args.format == "json":
print(json.dumps(result, indent=2))
else:
if "error" in result:
print(f"Error: {result['error']}")
else:
print(f"Title: {result.get('title')}")
print(f"Authors: {', '.join(result.get('authors', []))}")
print(f"arXiv URL: {result.get('arxiv_url')}")
print(f"\nAbstract:\n{result.get('abstract')}")
elif args.command == "citation":
citation = manager.generate_citation(args.arxiv_id, args.format)
print(citation)
elif args.command == "search":
print(f"Searching for: {args.query}")
print("Search functionality coming soon!")
print(f"Visit: https://huggingface.co/papers?search={args.query}")
if __name__ == "__main__":
main()
Requirements and compatibility
Works with: Claude Code, Claude apps, OpenAI Codex, GitHub Copilot, Cursor, Gemini CLI, Kiro, OpenCode, Goose, Amp, Roo Code, JetBrains Junie, Factory Droid, Devin (ex-Windsurf), Mistral Vibe, OpenHands, Letta
“Works with” means the tool reads the open Agent Skills format; a skill written for one tool may use features others lack.
Needs: Needs Python
Security
What our scanner noticed· Low risk
- Scripts that your agent may run
This skill includes scripts that your agent may run. Read them before you use it.
A static scan is not a guarantee. Skills are third-party content: review a skill before you let an agent use it.
Attribution and licence
- Published by
- Hugging Face
- Publisher
- Hugging Face (Official)
- Source
- huggingface/skills · skills/huggingface-paper-publisher · commit 25910b3
- Licence
- Apache License 2.0 (redistribution allowed)
- LICENSE (added by AutoGineer from LICENSE)
- ATTRIBUTION.md (written by AutoGineer)
- Synced
AutoGineer is not affiliated with or endorsed by Hugging Face or Hugging Face.
Download ZIP
The ZIP holds the skill’s files, its licence files and an ATTRIBUTION.md. Download huggingface-paper-publisher.zip