andito HF staff commited on
Commit
3180ac9
·
1 Parent(s): 7391bc6
Files changed (1) hide show
  1. app.py +42 -0
app.py ADDED
@@ -0,0 +1,42 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ from datasets import load_dataset, Dataset, concatenate_datasets
3
+ from datetime import datetime
4
+ import requests
5
+ import os
6
+
7
+ # Load your private Hugging Face dataset
8
+ DATASET_NAME = "andito/technical_interview_internship_2025"
9
+ TOKEN = os.environ.get("HF_TOKEN")
10
+ dataset = load_dataset(DATASET_NAME, split="train")
11
+
12
+ # Function to log download data to the HF Dataset
13
+ def log_to_hf_dataset(username):
14
+ if not username:
15
+ return "Please enter your username to proceed.", None
16
+
17
+ # Get current timestamp
18
+ timestamp = datetime.now().strftime("%Y-%m-%d %H:%M:%S")
19
+
20
+ # Append new data to the dataset
21
+ new_entry = Dataset.from_dict({
22
+ "username": [username],
23
+ "timestamp": [timestamp],
24
+ })
25
+ updated_dataset = concatenate_datasets([dataset, new_entry])
26
+ updated_dataset.push_to_hub(DATASET_NAME, token=TOKEN)
27
+
28
+ # Provide file for download
29
+ return "Thank you! Your download is ready.", "exercise.pdf" # Replace with your file path
30
+
31
+ # Gradio interface
32
+ with gr.Blocks() as demo:
33
+ username = gr.Textbox(label="Enter your username", placeholder="Your Hugging Face username")
34
+ download_button = gr.Button("Download Exercise")
35
+ output = gr.Text()
36
+ file = gr.File()
37
+
38
+ download_button.click(log_to_hf_dataset, inputs=[username], outputs=[output, file])
39
+
40
+ # Launch the app
41
+ demo.launch()
42
+