Spaces:
Running
Running
| import gradio as gr | |
| from huggingface_hub import HfApi | |
| from datasets import load_dataset, Dataset | |
| import os | |
| import uuid | |
| import json | |
| # Set your HF credentials | |
| HF_TOKEN = os.getenv("HF_TOKEN") | |
| DATASET_REPO = "huggingface/submitted-science-artifacts" | |
| # Load dataset (or create dummy if doesn't exist) | |
| def append_to_dataset(entry): | |
| try: | |
| # Load current dataset | |
| dataset = load_dataset(DATASET_REPO, split="train", token=HF_TOKEN) | |
| data = dataset.to_list() | |
| except Exception: | |
| data = [] | |
| # Append new entry | |
| data.append(entry) | |
| # Save locally and push | |
| new_dataset = Dataset.from_list(data) | |
| new_dataset.push_to_hub(DATASET_REPO, token=HF_TOKEN) | |
| def submit_paper(title, authors, abstract, category, paper_url, originality): | |
| if not originality: | |
| return "You must confirm that this is your own work." | |
| entry = { | |
| "id": str(uuid.uuid4()), | |
| "title": title, | |
| "authors": authors, | |
| "abstract": abstract, | |
| "category": category, | |
| "url": paper_url | |
| } | |
| append_to_dataset(entry) | |
| return "β Submission successful!" | |
| # Gradio interface | |
| with gr.Blocks() as demo: | |
| gr.Markdown("## π Submit Your Paper") | |
| with gr.Row(): | |
| title = gr.Textbox(label="Title", placeholder="Enter paper title") | |
| authors = gr.Textbox(label="Authors", placeholder="Jane Doe, John Smith") | |
| abstract = gr.Textbox(label="Description", lines=6) | |
| category = gr.Dropdown( | |
| label="Domain", | |
| choices=["Biology", "Chemistry", "Geospatial", "Climate", "Medicine", "Physics", "Energy", "Other"], | |
| value="Biology" | |
| ) | |
| paper_url = gr.Textbox(label="Paper URL (arXiv or PDF or just nice blog post)", placeholder="https://...") | |
| hf_url = gr.Textbox(label="Artifact URL (should be on the Hub)", placeholder="https://...") | |
| originality = gr.Checkbox(label="I confirm this is my own work") | |
| submit_btn = gr.Button("Submit") | |
| output = gr.Textbox(label="Status", interactive=False) | |
| submit_btn.click( | |
| fn=submit_paper, | |
| inputs=[title, authors, abstract, category, paper_url, hf_url, originality], | |
| outputs=output | |
| ) | |
| demo.launch() | |