102 lines
3.0 KiB
Python
102 lines
3.0 KiB
Python
|
|
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"
|
||
|
|
|
||
|
|
# 1. First, transcribe the audio
|
||
|
|
transcribe_payload = {
|
||
|
|
"media_url": audio_url,
|
||
|
|
"media_type": "audio"
|
||
|
|
}
|
||
|
|
|
||
|
|
transcribe_response = requests.post(
|
||
|
|
f"{base_url}/microdot-ai/transcribe",
|
||
|
|
headers=headers,
|
||
|
|
json=transcribe_payload
|
||
|
|
)
|
||
|
|
|
||
|
|
# Check if transcription was successful
|
||
|
|
if transcribe_response.status_code == 200:
|
||
|
|
transcript_data = transcribe_response.json()
|
||
|
|
print("Transcription successful!")
|
||
|
|
|
||
|
|
# Save the transcript for later use
|
||
|
|
transcript_json = json.dumps(transcript_data["transcript"], indent=4)
|
||
|
|
# Save the transcript to a file
|
||
|
|
with open("transcript.json", "w") as f:
|
||
|
|
f.write(transcript_json)
|
||
|
|
print("Transcript saved to transcript.json")
|
||
|
|
|
||
|
|
else:
|
||
|
|
print(f"Transcription failed with status code: {transcribe_response.status_code}")
|
||
|
|
print(transcribe_response.text)
|
||
|
|
|
||
|
|
|
||
|
|
|
||
|
|
# 2. Test the basic (Freemium) summarization
|
||
|
|
basic_summary_payload = {
|
||
|
|
"transcript": transcript_json,
|
||
|
|
"plan_tier": "freemium" # Specify the freemium plan
|
||
|
|
}
|
||
|
|
|
||
|
|
basic_summary_response = requests.post(
|
||
|
|
f"{base_url}/microdot-ai/general-summary",
|
||
|
|
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(
|
||
|
|
f"{base_url}/microdot-ai/general-summary",
|
||
|
|
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)
|
||
|
|
|
||
|
|
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)
|