2025-04-24 10:15:13 +01:00
|
|
|
import os
|
|
|
|
|
import requests
|
|
|
|
|
import json
|
|
|
|
|
from dotenv import load_dotenv
|
|
|
|
|
load_dotenv()
|
|
|
|
|
|
|
|
|
|
# API endpoint
|
|
|
|
|
base_url = "http://localhost:5056"
|
|
|
|
|
|
|
|
|
|
# Your API key
|
|
|
|
|
api_key = os.getenv("API_KEY_ACCESS")
|
|
|
|
|
|
|
|
|
|
# Headers
|
|
|
|
|
headers = {
|
|
|
|
|
"Authorization": f"Bearer {api_key}",
|
|
|
|
|
"Content-Type": "application/json"
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
# Audio URL from your notebook
|
|
|
|
|
audio_url = "https://s3.us-east-2.amazonaws.com/com.mkdlabs.images/baas/jordan/019933724441Business%20English%20Conversation%20Lesson%2045_%20Meeting%20a%20New%20Colleague.mp3"
|
|
|
|
|
|
2025-04-24 17:18:53 +01:00
|
|
|
# 1. First, transcribe the audio with the Pro plan (with speaker identification)
|
|
|
|
|
pro_transcribe_payload = {
|
2025-04-24 10:15:13 +01:00
|
|
|
"media_url": audio_url,
|
2025-04-24 17:18:53 +01:00
|
|
|
"media_type": "audio",
|
|
|
|
|
"plan_tier": "pro" # Specify the pro plan to include speaker identification
|
2025-04-24 10:15:13 +01:00
|
|
|
}
|
|
|
|
|
|
2025-04-24 17:18:53 +01:00
|
|
|
pro_transcribe_response = requests.post(
|
|
|
|
|
f"{base_url}/microdot-ai/transcribe",
|
2025-04-24 10:15:13 +01:00
|
|
|
headers=headers,
|
2025-04-24 17:18:53 +01:00
|
|
|
json=pro_transcribe_payload
|
2025-04-24 10:15:13 +01:00
|
|
|
)
|
|
|
|
|
|
2025-04-24 17:18:53 +01:00
|
|
|
# Check if Pro plan transcription was successful
|
|
|
|
|
if pro_transcribe_response.status_code == 200:
|
|
|
|
|
pro_transcript_data = pro_transcribe_response.json()
|
|
|
|
|
print("Pro plan transcription successful!")
|
|
|
|
|
|
|
|
|
|
# Save the Pro plan transcript for later use
|
|
|
|
|
pro_transcript_json = json.dumps(pro_transcript_data["transcript"], indent=4)
|
|
|
|
|
# Save the Pro plan transcript to a file
|
|
|
|
|
with open("pro_transcript.json", "w") as f:
|
|
|
|
|
f.write(pro_transcript_json)
|
|
|
|
|
print("Pro plan transcript saved to pro_transcript.json")
|
|
|
|
|
|
|
|
|
|
# Check if the Pro plan transcript has speaker information
|
|
|
|
|
has_speaker_pro = "speaker" in pro_transcript_data["transcript"]["sentences"][0] if pro_transcript_data["transcript"]["sentences"] else False
|
|
|
|
|
print(f"Pro plan has speaker information: {has_speaker_pro}")
|
|
|
|
|
else:
|
|
|
|
|
print(f"Pro plan transcription failed with status code: {pro_transcribe_response.status_code}")
|
|
|
|
|
print(pro_transcribe_response.text)
|
|
|
|
|
|
|
|
|
|
# 1b. Now transcribe with the Free plan (without speaker identification)
|
|
|
|
|
free_transcribe_payload = {
|
|
|
|
|
"media_url": audio_url,
|
|
|
|
|
"media_type": "audio",
|
|
|
|
|
"plan_tier": "freemium" # Specify the freemium plan to exclude speaker identification
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
free_transcribe_response = requests.post(
|
|
|
|
|
f"{base_url}/microdot-ai/transcribe",
|
|
|
|
|
headers=headers,
|
|
|
|
|
json=free_transcribe_payload
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
# Check if Free plan transcription was successful
|
|
|
|
|
if free_transcribe_response.status_code == 200:
|
|
|
|
|
free_transcript_data = free_transcribe_response.json()
|
|
|
|
|
print("Free plan transcription successful!")
|
|
|
|
|
|
|
|
|
|
# Save the Free plan transcript for later use
|
|
|
|
|
free_transcript_json = json.dumps(free_transcript_data["transcript"], indent=4)
|
|
|
|
|
# Save the Free plan transcript to a file
|
|
|
|
|
with open("free_transcript.json", "w") as f:
|
|
|
|
|
f.write(free_transcript_json)
|
|
|
|
|
print("Free plan transcript saved to free_transcript.json")
|
2025-04-24 10:15:13 +01:00
|
|
|
|
2025-04-24 17:18:53 +01:00
|
|
|
# Check if the Free plan transcript has speaker information
|
|
|
|
|
has_speaker_free = "speaker" in free_transcript_data["transcript"]["sentences"][0] if free_transcript_data["transcript"]["sentences"] else False
|
|
|
|
|
print(f"Free plan has speaker information: {has_speaker_free}")
|
|
|
|
|
|
|
|
|
|
# Use the Pro plan transcript for the summary tests
|
|
|
|
|
transcript_json = pro_transcript_json
|
2025-04-24 10:15:13 +01:00
|
|
|
else:
|
2025-04-24 17:18:53 +01:00
|
|
|
print(f"Free plan transcription failed with status code: {free_transcribe_response.status_code}")
|
|
|
|
|
print(free_transcribe_response.text)
|
|
|
|
|
|
|
|
|
|
# If Free plan fails but Pro plan succeeded, use Pro plan transcript for summary tests
|
|
|
|
|
if pro_transcribe_response.status_code == 200:
|
|
|
|
|
transcript_json = pro_transcript_json
|
2025-04-24 10:15:13 +01:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# 2. Test the basic (Freemium) summarization
|
|
|
|
|
basic_summary_payload = {
|
|
|
|
|
"transcript": transcript_json,
|
|
|
|
|
"plan_tier": "freemium" # Specify the freemium plan
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
basic_summary_response = requests.post(
|
2025-04-24 17:18:53 +01:00
|
|
|
f"{base_url}/microdot-ai/general-summary",
|
2025-04-24 10:15:13 +01:00
|
|
|
headers=headers,
|
|
|
|
|
json=basic_summary_payload
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
# Check if summarization was successful
|
|
|
|
|
if basic_summary_response.status_code == 200:
|
|
|
|
|
basic_summary_data = basic_summary_response.json()
|
|
|
|
|
print("\n--- Basic (Freemium) Summary ---")
|
|
|
|
|
basic_summary_json = json.dumps(basic_summary_data, indent=2)
|
|
|
|
|
|
|
|
|
|
with open("basic_summary.json", "w") as f:
|
|
|
|
|
f.write(basic_summary_json)
|
|
|
|
|
print("Basic summary saved to basic_summary.json")
|
|
|
|
|
|
|
|
|
|
else:
|
|
|
|
|
print(f"Basic summarization failed with status code: {basic_summary_response.status_code}")
|
|
|
|
|
print(basic_summary_response.text)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# 3. Test the advanced (Pro) summarization
|
|
|
|
|
advanced_summary_payload = {
|
|
|
|
|
"transcript": transcript_json,
|
|
|
|
|
"plan_tier": "pro" # Specify the pro plan
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
advanced_summary_response = requests.post(
|
2025-04-24 17:18:53 +01:00
|
|
|
f"{base_url}/microdot-ai/general-summary",
|
2025-04-24 10:15:13 +01:00
|
|
|
headers=headers,
|
|
|
|
|
json=advanced_summary_payload
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
# Check if summarization was successful
|
|
|
|
|
if advanced_summary_response.status_code == 200:
|
|
|
|
|
advanced_summary_data = advanced_summary_response.json()
|
|
|
|
|
print("\n--- Advanced (Pro) Summary ---")
|
|
|
|
|
advanced_summary_json = json.dumps(advanced_summary_data, indent=2)
|
2025-04-24 17:18:53 +01:00
|
|
|
|
2025-04-24 10:15:13 +01:00
|
|
|
with open("advanced_summary.json", "w") as f:
|
|
|
|
|
f.write(advanced_summary_json)
|
|
|
|
|
print("Advanced summary saved to advanced_summary.json")
|
|
|
|
|
else:
|
|
|
|
|
print(f"Advanced summarization failed with status code: {advanced_summary_response.status_code}")
|
|
|
|
|
print(advanced_summary_response.text)
|