|
24 | 24 | ) |
25 | 25 |
|
26 | 26 | print("Analysis received:") |
27 | | - print(f"Sentiment: {response.sentiment}") |
28 | | - if response.summary: |
29 | | - print(f"Summary: {response.summary}") |
30 | | - if response.topics: |
31 | | - print(f"Topics: {response.topics}") |
32 | | - if response.intents: |
33 | | - print(f"Intents: {response.intents}") |
| 27 | + |
| 28 | + # Access results from the response.results object |
| 29 | + if response.results.sentiments: |
| 30 | + if response.results.sentiments.average: |
| 31 | + print(f"Average Sentiment: {response.results.sentiments.average.sentiment} (score: {response.results.sentiments.average.sentiment_score})") |
| 32 | + if response.results.sentiments.segments: |
| 33 | + print(f"Sentiment segments: {len(response.results.sentiments.segments)} found") |
| 34 | + |
| 35 | + if response.results.summary: |
| 36 | + if response.results.summary.results and response.results.summary.results.summary: |
| 37 | + print(f"Summary: {response.results.summary.results.summary.summary}") |
| 38 | + |
| 39 | + if response.results.topics: |
| 40 | + if response.results.topics.results and response.results.topics.results.topics: |
| 41 | + segments = response.results.topics.results.topics.segments |
| 42 | + if segments: |
| 43 | + print(f"Topics found: {len(segments)} segments") |
| 44 | + # Access topics from segments |
| 45 | + for segment in segments[:3]: # Show first 3 segments |
| 46 | + if segment.topics: |
| 47 | + topic_names = [topic.topic for topic in segment.topics if hasattr(topic, 'topic')] |
| 48 | + if topic_names: |
| 49 | + print(f" - {', '.join(topic_names)}") |
| 50 | + |
| 51 | + if response.results.intents: |
| 52 | + if response.results.intents.results and response.results.intents.results.intents: |
| 53 | + segments = response.results.intents.results.intents.segments |
| 54 | + if segments: |
| 55 | + print(f"Intents found: {len(segments)} segments") |
| 56 | + # Access intents from segments |
| 57 | + for segment in segments[:3]: # Show first 3 segments |
| 58 | + if segment.intents: |
| 59 | + intent_names = [intent.intent for intent in segment.intents if hasattr(intent, 'intent')] |
| 60 | + if intent_names: |
| 61 | + print(f" - {', '.join(intent_names)}") |
34 | 62 |
|
35 | 63 | # For async version: |
36 | 64 | # from deepgram import AsyncDeepgramClient |
37 | 65 | # client = AsyncDeepgramClient() |
38 | | - # response = await client.read.v1.text.analyze(...) |
| 66 | + # response = await client.read.v1.text.analyze( |
| 67 | + # request={"text": "Hello, world! This is a sample text for analysis."}, |
| 68 | + # language="en", |
| 69 | + # sentiment=True, |
| 70 | + # summarize=True, |
| 71 | + # topics=True, |
| 72 | + # intents=True, |
| 73 | + # ) |
| 74 | + |
| 75 | + # With access token: |
| 76 | + # client = DeepgramClient(access_token="your-access-token") |
39 | 77 |
|
40 | 78 | except Exception as e: |
41 | 79 | print(f"Error: {e}") |
0 commit comments