import json from paper2slides import Paper2Slides, PaperReader import os def read_json(file_path: str): try: with open(file_path, "r") as json_file: data = json.load(json_file) return data except FileNotFoundError: print(f"Error: The file '{file_path}' was not found.") return None except json.JSONDecodeError: print(f"Error: The file '{file_path}' is not a valid JSON.") return None def get_file_name(full_path: str): file_name = os.path.splitext(os.path.basename(full_path))[0] return file_name def run_pdf2text(paper_pdf_path: str, save_json_name: str): reader = PaperReader() paper_content = reader.run(paper_file_name=paper_pdf_path) # Save the dictionary as a JSON file with open(save_json_name, 'w') as json_file: json.dump(paper_content, json_file, indent=4) return paper_content def run_paper2slides(paper_json_name: str, model='llama3_70b', temprature=0.2, logo_path='logo.png', save_file_name:str='slides.pptx'): paper_content = read_json(paper_json_name) paper2slides = Paper2Slides(paper_contents=paper_content, model=model, temprature=temprature) slides = paper2slides.generate_slides(verbose=False, revision=False) with open('slides.json', 'w') as f: json.dump(slides, f, indent=4) # indent=4 makes it pretty-printed assert isinstance(slides, dict) return paper2slides.save_to_slides(slides=slides, logo_path=logo_path, file_name=save_file_name)