Last active
May 16, 2024 00:28
-
-
Save themacmarketer/4517f5a79ff4e8c9b043c94dbb819d91 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#Install meta.api using pip install meta-ai-api | |
#Reference: https://github.com/Strvm/meta-ai-api | |
import os | |
import time | |
from meta_ai_api import MetaAI | |
ai = MetaAI() | |
# Get all text files in the current directory | |
text_files = [f for f in os.listdir() if f.endswith('.txt')] | |
for file_name in text_files: | |
# Determine the new file name | |
new_file_name = file_name.replace('.txt', ' - Summarized.txt') | |
# Check if the output file already exists | |
if not os.path.exists(new_file_name): | |
# Read the content of each file | |
with open(file_name, 'r', encoding='utf-8') as file: | |
content = file.read() | |
# Generate a summary using the MetaAI | |
prompt = "Please summarize: " + content | |
response = ai.prompt(message=prompt) | |
# Prepare the output content | |
output_content = "Summary:\n" + response['message'] + "\n\nOriginal Transcript:\n" + content | |
# Write the output to a new file | |
with open(new_file_name, 'w', encoding='utf-8') as output_file: | |
output_file.write(output_content) | |
print(f"Processed and saved: {new_file_name}") | |
# Pause for 3 seconds before the next API call | |
time.sleep(3) | |
else: | |
print(f"File already exists: {new_file_name}") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment