File size: 1,352 Bytes
3180ac9
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
import gradio as gr
from datasets import load_dataset, Dataset, concatenate_datasets
from datetime import datetime
import requests
import os

# Load your private Hugging Face dataset
DATASET_NAME = "andito/technical_interview_internship_2025"
TOKEN = os.environ.get("HF_TOKEN")
dataset = load_dataset(DATASET_NAME, split="train")

# Function to log download data to the HF Dataset
def log_to_hf_dataset(username):
    if not username:
        return "Please enter your username to proceed.", None

    # Get current timestamp
    timestamp = datetime.now().strftime("%Y-%m-%d %H:%M:%S")

    # Append new data to the dataset
    new_entry = Dataset.from_dict({
        "username": [username],
        "timestamp": [timestamp],
    })
    updated_dataset = concatenate_datasets([dataset, new_entry])
    updated_dataset.push_to_hub(DATASET_NAME, token=TOKEN)

    # Provide file for download
    return "Thank you! Your download is ready.", "exercise.pdf"  # Replace with your file path

# Gradio interface
with gr.Blocks() as demo:
    username = gr.Textbox(label="Enter your username", placeholder="Your Hugging Face username")
    download_button = gr.Button("Download Exercise")
    output = gr.Text()
    file = gr.File()
    
    download_button.click(log_to_hf_dataset, inputs=[username], outputs=[output, file])

# Launch the app
demo.launch()