Spaces:
Sleeping
Sleeping
Download csv_cache.py from sagsan/Final_Assignment_Template: direct link, hf CLI and curl.
- Browser
- Download file 1.05 kB
-
https://huggingface.co/spaces/sagsan/Final_Assignment_Template/resolve/main/csv_cache.py
- Command line
-
hf download hf://spaces/sagsan/Final_Assignment_Template/csv_cache.py
-
curl -L -o csv_cache.py https://huggingface.co/spaces/sagsan/Final_Assignment_Template/resolve/main/csv_cache.py
1.05 kB
| import pandas as pd | |
| import os | |
| class CSVSCache: | |
| def __init__(self, filename="results.csv"): | |
| self.filename = filename | |
| self.df = self._load_cache() | |
| def _load_cache(self): | |
| if os.path.exists(self.filename): | |
| return pd.read_csv(self.filename) | |
| return pd.DataFrame(columns=["task_id", "question", "answer"]) | |
| def _save_cache(self): | |
| self.df.to_csv(self.filename, index=False) | |
| def get_all_entries(self): | |
| return self.df | |
| def get_answer(self, question): | |
| match = self.df[self.df['question'] == question].head() | |
| # Check if any matches were found | |
| if not match.empty: | |
| return match['answer'].iloc[0] | |
| else: | |
| return "unknown" | |
| def main(): | |
| csv = CSVSCache() | |
| print("done") | |
| q = "Where were the Vietnamese specimens described by Kuznetzov in Nedoshivina's 2010 paper eventually deposited? Just give me the city name without abbreviations." | |
| print(csv.get_answer(q)) | |
| if __name__ == "__main__": | |
| main() | |