Download transcripts_editing.py from gamora/ShortsAI: direct link, hf CLI and curl.
- Browser
- Download file 1.78 kB
-
https://huggingface.co/spaces/gamora/ShortsAI/resolve/main/transcripts_editing.py
- Command line
-
hf download hf://spaces/gamora/ShortsAI/transcripts_editing.py
-
curl -L -o transcripts_editing.py https://huggingface.co/spaces/gamora/ShortsAI/resolve/main/transcripts_editing.py
1.78 kB
| from dotenv import load_dotenv | |
| import requests | |
| import os | |
| load_dotenv() | |
| # Access the variables | |
| api_key = os.getenv("DEVICE_ID") | |
| def parse_response(data): | |
| dialog = [] | |
| for i in range(len(data['memories'])): | |
| for segment in data['memories'][i]['transcript_segments']: | |
| speaker = segment['speaker'] | |
| start_time = segment['start'] | |
| end_time = segment['end'] | |
| # Fallback for unexpected speaker IDs | |
| dialog.append(f"**{speaker}**: {segment['text']}") | |
| # Join dialog lines into a markdown string | |
| dialog_text = "\n\n".join(dialog) | |
| return dialog_text | |
| def fetch_memories(url, headers, cursor=None): | |
| # Update URL with cursor if provided | |
| if cursor: | |
| url = f"{url}&cursor={cursor}" | |
| response = requests.get(url, headers=headers) | |
| if response.status_code == 200: | |
| return response.json() | |
| else: | |
| print(f"Error: {response.status_code} - {response.text}") | |
| return None | |
| # Initial API setup | |
| def get_dialog(date="2025-08-21"): | |
| url = "https://apis.getbuddi.ai/v1/dev/get_memories?date="+date | |
| headers = { | |
| "api-key": api_key | |
| } | |
| dialog="" | |
| # Fetch first batch | |
| data = fetch_memories(url, headers) | |
| if data: | |
| # print("First batch:", data) | |
| # Check for next_cursor and fetch subsequent batches | |
| while 'next_cursor' in data and data['next_cursor']: | |
| cursor = data['next_cursor'] | |
| print(cursor) | |
| data = fetch_memories(url, headers, cursor) | |
| if data: | |
| dialog=dialog+parse_response(data) | |
| # print("Next batch:", data) | |
| else: | |
| break | |
| return(dialog) | |
| if __name__ == "__main__": | |
| print(get_dialog()) |