satyamr196's picture
Major Update : created all the routes reqired, add utils folder containing helper fxns
547836e
from dotenv import load_dotenv
from huggingface_hub import HfApi, hf_hub_download
import os
import io
import pandas as pd
# Load environment variables from .env file
load_dotenv()
# ASR_model = "openai/whisper-largev2" # Replace with your ASR model
# csv_path = "test.csv" #read from local
# csv_transcript = f"test_with_{ASR_model.replace("/","_")}.csv" # to save in dataset repo
# csv_result = f"test_with_{ASR_model.replace("/","_")}_WER.csv" # to save in dataset repo
# df = pd.read_csv(csv_path)
# print(f"CSV Loaded with {len(df)} rows")
def upload_csv(df,csv_filename):
csv_buffer = io.BytesIO()
df.to_csv(csv_buffer, index=False)
csv_buffer.seek(0)
try:
# Upload the generated csv to Hugging Face Hub
api = HfApi(token=os.getenv("HF_TOKEN"))
print(f"✅ CSV uploading : {csv_filename}")
api.upload_file(
path_or_fileobj=csv_buffer,
path_in_repo=csv_filename,
repo_id="satyamr196/asr_fairness_results",
repo_type="dataset"
)
return True
except Exception as e:
print(f"⚠️ Could not upload CSV: {csv_filename}{e}")
return False
# upload_csv(df,f"test_with_{ASR_model.replace("/","_")}_WER.csv");
def download_csv(csv_filename):
repo_id = "satyamr196/asr_fairness_results"
try:
# Download the CSV file from the dataset repo
csv_path = hf_hub_download(repo_id=repo_id, filename=csv_filename, repo_type="dataset")
# Load into pandas
return pd.read_csv(csv_path)
except Exception as e:
# print(f"⚠️ Could not load CSV: {csv_filename} — {e}")
return None
# # # Load the csv from the Hugging Face Hub
# df = download_csv(csv_result)
# if(df is None):
# print(f"CSV not found in the dataset repo. Please upload the file first.")
# else:
# print(f"CSV Loaded with {len(df)} rows")
# print(df)