Spaces:
Sleeping
Sleeping
Download utils/save_to_document.py from Swaraj2003/smarttrip_ai: direct link, hf CLI and curl.
- Browser
- Download file 1.21 kB
-
https://huggingface.co/spaces/Swaraj2003/smarttrip_ai/resolve/main/utils/save_to_document.py
- Command line
-
hf download hf://spaces/Swaraj2003/smarttrip_ai/utils/save_to_document.py
-
curl -L -o save_to_document.py https://huggingface.co/spaces/Swaraj2003/smarttrip_ai/resolve/main/utils/save_to_document.py
1.21 kB
| import os | |
| import datetime | |
| def save_document(response_text: str, directory: str = "./output"): | |
| """Export travel plan to Markdown file with proper formatting""" | |
| os.makedirs(directory, exist_ok=True) | |
| # Create markdown content with metadata header | |
| markdown_content = f"""# 🌍 AI Travel Plan | |
| # **Generated:** {datetime.datetime.now().strftime('%Y-%m-%d at %H:%M')} | |
| # **Created by:** Atriyo's Travel Agent | |
| --- | |
| {response_text} | |
| --- | |
| *This travel plan was generated by AI. Please verify all information, especially prices, operating hours, and travel requirements before your trip.* | |
| """ | |
| try: | |
| # Write to markdown file with UTF-8 encoding | |
| # Generate timestamp-based filename | |
| timestamp = datetime.datetime.now().strftime("%Y-%m-%d_%H-%M-%S") | |
| filename = f"{directory}/AI_Trip_Planner_{timestamp}.md" | |
| print(filename) | |
| with open(filename, 'w', encoding='utf-8') as f: | |
| f.write(markdown_content) | |
| print(f"Markdown file saved as: {filename}") | |
| return filename | |
| except Exception as e: | |
| print(f"Error saving markdown file: {e}") | |
| return None |