File size: 1,035 Bytes
d506fd2
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import os
import gradio as gr
from datasets import Dataset
from huggingface_hub import HfApi, HfFolder

# Get the Hugging Face token from the environment variable
hf_token = os.getenv("HF_TOKEN")

def upload_to_huggingface(file):
    # Load the CSV file into a Hugging Face Dataset
    dataset = Dataset.from_csv(file.name)
    
    # Authenticate using the Hugging Face token
    api = HfApi()
    api.upload_file(
        path_or_fileobj=file.name,
        path_in_repo="advertising.csv",
        repo_id="wvsu-dti-aidev-team/advertising_sales_regression",
        repo_type="dataset",
        token=hf_token
    )
    
    return "Dataset uploaded successfully!"

# Create a Gradio interface
iface = gr.Interface(
    fn=upload_to_huggingface,
    inputs=gr.File(label="Upload CSV File"),
    outputs="text",
    title="Upload Dataset to Hugging Face",
    description="Upload the advertising.csv dataset to the Hugging Face Hub repository wvsu-dti-aidev-team/advertising_sales_regression."
)

# Launch the Gradio app
iface.launch()