test_2024 / app.py
andito's picture
andito HF staff
start
3180ac9
raw
history blame
1.35 kB
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()