This repository was archived by the owner on May 19, 2026. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathapp_simple.py
More file actions
2372 lines (2038 loc) · 96.2 KB
/
Copy pathapp_simple.py
File metadata and controls
2372 lines (2038 loc) · 96.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
# WhisperForge Simple - Clean, Focused Audio Content Platform
import streamlit as st
import os
import tempfile
import time
from datetime import datetime
from typing import Dict, Optional
# Essential imports only
from dotenv import load_dotenv
load_dotenv()
# Page config first
st.set_page_config(
page_title="WhisperForge",
page_icon="🌌",
layout="wide"
)
# Core imports
from core.content_generation import transcribe_audio, generate_wisdom, generate_outline, generate_article, generate_social_content
from core.styling import apply_aurora_theme, create_aurora_header, create_aurora_progress_card, create_aurora_step_card, create_aurora_content_card, AuroraComponents
from core.supabase_integration import get_supabase_client
from core.file_upload import EnhancedLargeFileProcessor
# Apply beautiful theme
apply_aurora_theme()
# === PROMPT LOADING SYSTEM ===
def load_custom_prompts():
"""Load custom prompts from the prompts directory"""
prompts = {}
prompt_dir = "prompts/default"
if os.path.exists(prompt_dir):
for filename in os.listdir(prompt_dir):
if filename.endswith('.md'):
prompt_name = filename.replace('.md', '')
try:
with open(os.path.join(prompt_dir, filename), 'r', encoding='utf-8') as f:
prompts[prompt_name] = f.read()
except Exception as e:
st.warning(f"Failed to load prompt {filename}: {e}")
return prompts
def load_template(template_name: str) -> Optional[str]:
"""Load an article template by name"""
template_path = os.path.join('templates', f'{template_name}.md')
if os.path.exists(template_path):
return open(template_path, 'r', encoding='utf-8').read()
return None
def get_prompt_for_step(step_name: str, custom_prompts: Dict[str, str] = None) -> Optional[str]:
"""Get the appropriate prompt for a pipeline step"""
if not custom_prompts:
custom_prompts = load_custom_prompts()
# Map step names to prompt files
prompt_mapping = {
'wisdom': 'wisdom_extraction',
'outline': 'outline_creation',
'social': 'social_media',
'article': 'article_generation' # We'll create this
}
prompt_key = prompt_mapping.get(step_name)
if prompt_key and prompt_key in custom_prompts:
return custom_prompts[prompt_key]
return None
# === NOTION INTEGRATION ===
def create_notion_page(title: str, content_data: Dict[str, str]) -> Optional[str]:
"""Create a Notion page with WhisperForge content"""
try:
from notion_client import Client
api_key = os.getenv("NOTION_API_KEY")
database_id = os.getenv("NOTION_DATABASE_ID")
if not api_key or not database_id:
st.warning("⚠️ Notion not configured. Set NOTION_API_KEY and NOTION_DATABASE_ID to auto-publish.")
return None
client = Client(auth=api_key)
# Build content blocks
children = []
# Add beautiful header with summary
children.append({
"type": "heading_1",
"heading_1": {
"rich_text": [
{"type": "text", "text": {"content": "🌌 "}, "annotations": {"color": "blue"}},
{"type": "text", "text": {"content": title}, "annotations": {"bold": True}}
]
}
})
# Add creation info
children.append({
"type": "paragraph",
"paragraph": {
"rich_text": [
{"type": "text", "text": {"content": "✨ Generated with "}},
{"type": "text", "text": {"content": "WhisperForge Aurora"},
"annotations": {"bold": True, "color": "blue"}},
{"type": "text", "text": {"content": f" • {datetime.now().strftime('%B %d, %Y at %I:%M %p')}"}}
]
}
})
children.append({"type": "divider", "divider": {}})
# Add wisdom summary callout if exists
if content_data.get('wisdom'):
children.append({
"type": "callout",
"callout": {
"rich_text": [
{"type": "text", "text": {"content": "Key Insights & Wisdom"}},
{"type": "text", "text": {"content": f"\n\n{content_data['wisdom'][:1800]}"}}
],
"color": "purple_background",
"icon": {"type": "emoji", "emoji": "💡"}
}
})
# Add content sections as toggles
sections = [
("📝 Transcript", content_data.get('transcript')),
("💡 Wisdom", content_data.get('wisdom')),
("🔍 Research Links", content_data.get('research')),
("📋 Outline", content_data.get('outline')),
("📰 Article", content_data.get('article')),
("📱 Social Content", content_data.get('social_content'))
]
for section_title, section_content in sections:
if section_content:
# Handle research data specially
if section_title == "🔍 Research Links" and isinstance(section_content, dict):
research_children = []
entities = section_content.get('entities', [])
if entities:
for entity in entities[:5]: # Limit entities
entity_name = entity.get('name', 'Unknown Entity')
why_matters = entity.get('why_matters', 'No description available')
links = entity.get('links', [])
# Entity as beautiful callout
research_children.append({
"type": "callout",
"callout": {
"rich_text": [
{"type": "text", "text": {"content": entity_name}, "annotations": {"bold": True}},
{"type": "text", "text": {"content": f"\n{why_matters}"}}
],
"color": "blue_background",
"icon": {"type": "emoji", "emoji": "🔬"}
}
})
# Links as bulleted list
if links:
for link in links[:3]: # Limit links
link_title = link.get('title', 'Link')
link_url = link.get('url', '#')
link_desc = link.get('description', '')
is_gem = link.get('is_gem', False)
gem_icon = "💎" if is_gem else "🔗"
color = "orange" if is_gem else "default"
research_children.append({
"type": "bulleted_list_item",
"bulleted_list_item": {
"rich_text": [
{"type": "text", "text": {"content": f"{gem_icon} "}, "annotations": {"color": color}},
{"type": "text", "text": {"content": link_title}, "annotations": {"bold": True}},
{"type": "text", "text": {"content": f" - {link_desc}"}, "annotations": {"italic": True}}
]
}
})
else:
research_children.append({
"type": "paragraph",
"paragraph": {
"rich_text": [{"type": "text", "text": {"content": "No research entities found."}}]
}
})
children.append({
"type": "toggle",
"toggle": {
"rich_text": [{"type": "text", "text": {"content": section_title}}],
"children": research_children
}
})
else:
# Handle regular text content
if isinstance(section_content, str):
# Chunk content for Notion's limits
chunks = [section_content[i:i+1800] for i in range(0, len(section_content), 1800)]
children.append({
"type": "toggle",
"toggle": {
"rich_text": [{"type": "text", "text": {"content": section_title}}],
"children": [
{
"type": "paragraph",
"paragraph": {
"rich_text": [{"type": "text", "text": {"content": chunk}}]
}
} for chunk in chunks[:5] # Limit chunks
]
}
})
# Add beautiful footer
children.extend([
{"type": "divider", "divider": {}},
{
"type": "callout",
"callout": {
"rich_text": [
{"type": "text", "text": {"content": "Content Generation Complete"}, "annotations": {"bold": True}},
{"type": "text", "text": {"content": f"\n\n🤖 AI Pipeline: 8 steps completed successfully"}},
{"type": "text", "text": {"content": f"\n⏱️ Generated: {datetime.now().strftime('%B %d, %Y at %I:%M %p')}"}},
{"type": "text", "text": {"content": f"\n🌌 Powered by WhisperForge Aurora"}}
],
"color": "green_background",
"icon": {"type": "emoji", "emoji": "✅"}
}
}
])
# Create the page
response = client.pages.create(
parent={"database_id": database_id},
icon={"type": "emoji", "emoji": "🌌"},
properties={
"Name": {"title": [{"text": {"content": title[:100]}}]}
},
children=children[:50] # Limit total blocks
)
if response and 'id' in response:
page_id = response['id']
page_url = f"https://notion.so/{page_id.replace('-', '')}"
return page_url
return None
except ImportError:
st.warning("⚠️ Install notion-client to enable Notion publishing: pip install notion-client")
return None
except Exception as e:
st.error(f"❌ Notion publishing failed: {str(e)}")
return None
def generate_ai_title(transcript: str) -> str:
"""Generate an AI title for the content"""
try:
from core.content_generation import generate_content
prompt = f"""Generate a concise, descriptive title (max 60 characters) for this audio transcript:
{transcript[:500]}...
Title should be:
- Clear and specific
- Professional
- Capture the main topic
- No quotes or special characters
Title:"""
title = generate_content(prompt, "OpenAI", "gpt-4", {})
return title.strip().replace('"', '').replace("'", "")[:60]
except:
return f"WhisperForge Content - {datetime.now().strftime('%Y-%m-%d %H:%M')}"
# === SIMPLE AUTHENTICATION ===
def init_session():
"""Initialize simple session state"""
if 'authenticated' not in st.session_state:
st.session_state.authenticated = False
if 'user_id' not in st.session_state:
st.session_state.user_id = None
if 'user_email' not in st.session_state:
st.session_state.user_email = None
def show_login():
"""Simple test login"""
create_aurora_header()
st.markdown("### 🔐 Login to WhisperForge")
# Test login button
if st.button("🚀 Login with Test Account", type="primary", use_container_width=True):
st.session_state.authenticated = True
st.session_state.user_id = 1
st.session_state.user_email = "test@whisperforge.ai"
st.success("✅ Logged in successfully!")
time.sleep(1)
st.rerun()
st.markdown("---")
st.markdown("**Demo Mode**: Click above to access WhisperForge")
# === CORE PROCESSING PIPELINE ===
def show_processing_pipeline(current_step=0, step_progress=0, total_progress=0, status_message="", processing_time=""):
"""Display beautiful Aurora-styled processing pipeline visualization"""
# Define the 6-step pipeline
pipeline_steps = [
{
"icon": "🎤",
"title": "Transcription",
"description": "Converting audio to text using Whisper AI",
"status": "pending"
},
{
"icon": "💡",
"title": "Wisdom Extraction",
"description": "Extracting key insights and wisdom",
"status": "pending"
},
{
"icon": "📋",
"title": "Outline Creation",
"description": "Structuring content with clear outline",
"status": "pending"
},
{
"icon": "📰",
"title": "Article Generation",
"description": "Creating comprehensive article content",
"status": "pending"
},
{
"icon": "📱",
"title": "Social Content",
"description": "Generating social media posts",
"status": "pending"
},
{
"icon": "🌌",
"title": "Notion Publishing",
"description": "Publishing to Notion workspace",
"status": "pending"
}
]
# Update step statuses based on current progress
for i, step in enumerate(pipeline_steps):
if i < current_step:
step["status"] = "completed"
elif i == current_step:
step["status"] = "active"
else:
step["status"] = "pending"
# Create the pipeline visualization HTML
steps_html = ""
for i, step in enumerate(pipeline_steps):
progress_width = step_progress if i == current_step else (100 if step["status"] == "completed" else 0)
status_text = {
"pending": "Waiting",
"active": "Processing",
"completed": "Complete",
"error": "Error"
}.get(step["status"], "Waiting")
steps_html += f"""
<div class="aurora-pipeline-step {step['status']}">
<div class="aurora-step-progress" style="width: {progress_width}%;"></div>
<span class="aurora-step-icon">{step['icon']}</span>
<h4 class="aurora-step-title">{step['title']}</h4>
<p class="aurora-step-description">{step['description']}</p>
<div class="aurora-step-status">{status_text}</div>
</div>
"""
# Create the complete pipeline HTML
pipeline_html = f"""
<div class="aurora-pipeline-container">
<div class="aurora-pipeline-header">
<h3 class="aurora-pipeline-title">Content Transformation Pipeline</h3>
<p class="aurora-pipeline-subtitle">6-Step AI-Powered Processing</p>
</div>
<div class="aurora-overall-progress">
<div class="aurora-progress-header">
<span class="aurora-progress-label">Overall Progress</span>
<span class="aurora-progress-percentage">{total_progress}%</span>
</div>
<div class="aurora-progress-bar-container">
<div class="aurora-progress-bar" style="width: {total_progress}%;"></div>
</div>
</div>
<div class="aurora-pipeline-steps">
{steps_html}
</div>
{f'''
<div class="aurora-processing-status active">
<span class="aurora-status-icon">⚡</span>
<span class="aurora-status-text">{status_message}</span>
<span class="aurora-status-time">{processing_time}</span>
</div>
''' if status_message else ''}
</div>
"""
st.markdown(pipeline_html, unsafe_allow_html=True)
def process_audio_pipeline(audio_file):
"""Core audio to content pipeline with beautiful Aurora visualization"""
import time
from datetime import datetime
results = {}
start_time = time.time()
# Load custom prompts
custom_prompts = load_custom_prompts()
if custom_prompts:
st.info(f"📝 Using {len(custom_prompts)} custom prompts")
# Initialize beautiful pipeline visualization
pipeline_placeholder = st.empty()
# Create real-time content display containers
st.markdown("### 🌌 Live Content Generation")
# Create expandable containers for each step
transcript_container = st.expander("🎙️ Transcription", expanded=False)
wisdom_container = st.expander("💡 Wisdom Extraction", expanded=False)
outline_container = st.expander("📋 Outline Creation", expanded=False)
article_container = st.expander("📝 Article Generation", expanded=False)
social_container = st.expander("📱 Social Content", expanded=False)
notion_container = st.expander("🌌 Notion Publishing", expanded=False)
try:
# Step 1: Transcription
with pipeline_placeholder.container():
show_processing_pipeline(
current_step=0,
step_progress=0,
total_progress=0,
status_message="Starting transcription process...",
processing_time=f"{time.time() - start_time:.1f}s"
)
# Import transcription function
from core.content_generation import transcribe_audio
# Create temporary file
import tempfile
import os
with tempfile.NamedTemporaryFile(delete=False, suffix=os.path.splitext(audio_file.name)[1]) as tmp_file:
tmp_file.write(audio_file.getvalue())
tmp_file_path = tmp_file.name
try:
# Transcription with progress updates
with pipeline_placeholder.container():
show_processing_pipeline(
current_step=0,
step_progress=50,
total_progress=8,
status_message="Transcribing audio with Whisper AI...",
processing_time=f"{time.time() - start_time:.1f}s"
)
transcript = transcribe_audio(tmp_file_path)
if not transcript or "Error" in transcript:
st.error(f"Transcription failed: {transcript}")
return None
results['transcript'] = transcript
# Stream transcript to UI immediately
with transcript_container:
st.markdown("**✅ Transcription Complete**")
st.text_area("Transcript", transcript, height=200, disabled=True)
with pipeline_placeholder.container():
show_processing_pipeline(
current_step=0,
step_progress=100,
total_progress=17,
status_message="Transcription complete!",
processing_time=f"{time.time() - start_time:.1f}s"
)
# Step 2: Wisdom Extraction
with pipeline_placeholder.container():
show_processing_pipeline(
current_step=1,
step_progress=0,
total_progress=17,
status_message="Extracting wisdom and insights...",
processing_time=f"{time.time() - start_time:.1f}s"
)
from core.content_generation import generate_wisdom
wisdom_prompt = get_prompt_for_step('wisdom', custom_prompts)
with pipeline_placeholder.container():
show_processing_pipeline(
current_step=1,
step_progress=50,
total_progress=25,
status_message="Analyzing content for key insights...",
processing_time=f"{time.time() - start_time:.1f}s"
)
wisdom = generate_wisdom(transcript, custom_prompt=wisdom_prompt, knowledge_base={})
results['wisdom'] = wisdom
# Stream wisdom to UI immediately
with wisdom_container:
st.markdown("**✅ Wisdom Extraction Complete**")
st.markdown(wisdom)
with pipeline_placeholder.container():
show_processing_pipeline(
current_step=1,
step_progress=100,
total_progress=33,
status_message="Wisdom extraction complete!",
processing_time=f"{time.time() - start_time:.1f}s"
)
# Step 3: Outline Creation
with pipeline_placeholder.container():
show_processing_pipeline(
current_step=2,
step_progress=0,
total_progress=33,
status_message="Creating structured outline...",
processing_time=f"{time.time() - start_time:.1f}s"
)
from core.content_generation import generate_outline
outline_prompt = get_prompt_for_step('outline', custom_prompts)
with pipeline_placeholder.container():
show_processing_pipeline(
current_step=2,
step_progress=50,
total_progress=42,
status_message="Structuring content hierarchy...",
processing_time=f"{time.time() - start_time:.1f}s"
)
outline = generate_outline(transcript, wisdom, custom_prompt=outline_prompt, knowledge_base={})
results['outline'] = outline
# Stream outline to UI immediately
with outline_container:
st.markdown("**✅ Outline Creation Complete**")
st.markdown(outline)
with pipeline_placeholder.container():
show_processing_pipeline(
current_step=2,
step_progress=100,
total_progress=50,
status_message="Outline creation complete!",
processing_time=f"{time.time() - start_time:.1f}s"
)
# Step 4: Article Generation
with pipeline_placeholder.container():
show_processing_pipeline(
current_step=3,
step_progress=0,
total_progress=50,
status_message="Generating comprehensive article...",
processing_time=f"{time.time() - start_time:.1f}s"
)
from core.content_generation import generate_article
article_prompt = get_prompt_for_step('article', custom_prompts)
selected_template = st.session_state.get('article_template')
if selected_template:
template_text = load_template(selected_template)
if template_text:
article_prompt = template_text + "\n" + article_prompt
with pipeline_placeholder.container():
show_processing_pipeline(
current_step=3,
step_progress=50,
total_progress=58,
status_message="Writing detailed article content...",
processing_time=f"{time.time() - start_time:.1f}s"
)
article = generate_article(transcript, wisdom, outline, custom_prompt=article_prompt, knowledge_base={})
results['article'] = article
# Stream article to UI immediately
with article_container:
st.markdown("**✅ Article Generation Complete**")
st.markdown(article)
with pipeline_placeholder.container():
show_processing_pipeline(
current_step=3,
step_progress=100,
total_progress=67,
status_message="Article generation complete!",
processing_time=f"{time.time() - start_time:.1f}s"
)
# Step 5: Social Content
with pipeline_placeholder.container():
show_processing_pipeline(
current_step=4,
step_progress=0,
total_progress=67,
status_message="Creating social media content...",
processing_time=f"{time.time() - start_time:.1f}s"
)
from core.content_generation import generate_social_content
social_prompt = get_prompt_for_step('social', custom_prompts)
with pipeline_placeholder.container():
show_processing_pipeline(
current_step=4,
step_progress=50,
total_progress=75,
status_message="Generating social media posts...",
processing_time=f"{time.time() - start_time:.1f}s"
)
social = generate_social_content(wisdom, outline, article, custom_prompt=social_prompt, knowledge_base={})
results['social_content'] = social
# Stream social content to UI immediately
with social_container:
st.markdown("**✅ Social Content Creation Complete**")
st.markdown(social)
with pipeline_placeholder.container():
show_processing_pipeline(
current_step=4,
step_progress=100,
total_progress=83,
status_message="Social content creation complete!",
processing_time=f"{time.time() - start_time:.1f}s"
)
# Step 6: Auto-publish to Notion
with pipeline_placeholder.container():
show_processing_pipeline(
current_step=5,
step_progress=0,
total_progress=83,
status_message="Publishing to Notion workspace...",
processing_time=f"{time.time() - start_time:.1f}s"
)
if os.getenv("NOTION_API_KEY") and os.getenv("NOTION_DATABASE_ID"):
# Generate AI title
ai_title = generate_ai_title(transcript)
with pipeline_placeholder.container():
show_processing_pipeline(
current_step=5,
step_progress=30,
total_progress=88,
status_message="Creating Notion page structure...",
processing_time=f"{time.time() - start_time:.1f}s"
)
with pipeline_placeholder.container():
show_processing_pipeline(
current_step=5,
step_progress=60,
total_progress=92,
status_message="Uploading content to Notion...",
processing_time=f"{time.time() - start_time:.1f}s"
)
# Publish to Notion
notion_url = create_notion_page(ai_title, results)
if notion_url:
results['notion_url'] = notion_url
# Stream Notion success to UI
with notion_container:
st.markdown("**✅ Notion Publishing Complete**")
st.markdown(f"**Page Title:** {ai_title}")
st.markdown(f"🔗 [Open in Notion]({notion_url})")
else:
# Stream Notion failure to UI
with notion_container:
st.markdown("**⚠️ Notion Publishing Failed**")
st.warning("Check your Notion API configuration in Settings.")
else:
# Show disabled status in UI
with notion_container:
st.markdown("**ℹ️ Notion Publishing Disabled**")
st.info("Configure Notion API in Settings to enable auto-publishing.")
with pipeline_placeholder.container():
show_processing_pipeline(
current_step=5,
step_progress=90,
total_progress=96,
status_message="Saving to database...",
processing_time=f"{time.time() - start_time:.1f}s"
)
# Save to Supabase database
try:
save_content_to_db(results)
except Exception as e:
st.warning(f"⚠️ Content saved locally but database save failed: {e}")
with pipeline_placeholder.container():
show_processing_pipeline(
current_step=5,
step_progress=100,
total_progress=100,
status_message="Pipeline complete! All content generated successfully.",
processing_time=f"{time.time() - start_time:.1f}s"
)
# Aurora completion celebration
st.markdown("""
<div class="aurora-celebration">
<h1 class="aurora-celebration-title">Pipeline Complete!</h1>
<p class="aurora-celebration-subtitle">Your content has been transformed with AI magic</p>
</div>
""", unsafe_allow_html=True)
# Clear the pipeline display after a moment
time.sleep(2)
pipeline_placeholder.empty()
return results
finally:
# Cleanup temporary file
if os.path.exists(tmp_file_path):
os.unlink(tmp_file_path)
except Exception as e:
# Show error state
with pipeline_placeholder.container():
show_processing_pipeline(
current_step=0,
step_progress=0,
total_progress=0,
status_message=f"Error: {str(e)}",
processing_time=f"{time.time() - start_time:.1f}s"
)
st.error(f"Pipeline failed: {str(e)}")
return None
def process_audio_pipeline_live(audio_file):
"""Run pipeline with StreamingPipelineController"""
from core.streaming_pipeline import get_pipeline_controller
controller = get_pipeline_controller()
controller.start_pipeline(audio_file)
while controller.process_next_step():
pass
return controller.get_results()
def process_audio_pipeline_with_transcript(transcript: str):
"""Process audio pipeline with pre-transcribed content using beautiful Aurora visualization"""
import time
from datetime import datetime
results = {'transcript': transcript}
start_time = time.time()
# Load custom prompts
custom_prompts = load_custom_prompts()
if custom_prompts:
st.info(f"📝 Using {len(custom_prompts)} custom prompts")
# Initialize beautiful pipeline visualization (starting from step 1)
pipeline_placeholder = st.empty()
# Create real-time content display containers
st.markdown("### 🌌 Live Content Generation")
# Create expandable containers for each step (skip transcription)
wisdom_container = st.expander("💡 Wisdom Extraction", expanded=False)
outline_container = st.expander("📋 Outline Creation", expanded=False)
article_container = st.expander("📝 Article Generation", expanded=False)
social_container = st.expander("📱 Social Content", expanded=False)
notion_container = st.expander("🌌 Notion Publishing", expanded=False)
try:
# Show initial state with transcription already complete
with pipeline_placeholder.container():
show_processing_pipeline(
current_step=1,
step_progress=0,
total_progress=17,
status_message=f"Using pre-transcribed content ({len(transcript)} characters)",
processing_time=f"{time.time() - start_time:.1f}s"
)
# Step 2: Wisdom Extraction
with pipeline_placeholder.container():
show_processing_pipeline(
current_step=1,
step_progress=0,
total_progress=17,
status_message="Extracting wisdom and insights...",
processing_time=f"{time.time() - start_time:.1f}s"
)
from core.content_generation import generate_wisdom
wisdom_prompt = get_prompt_for_step('wisdom', custom_prompts)
with pipeline_placeholder.container():
show_processing_pipeline(
current_step=1,
step_progress=50,
total_progress=25,
status_message="Analyzing content for key insights...",
processing_time=f"{time.time() - start_time:.1f}s"
)
wisdom = generate_wisdom(transcript, custom_prompt=wisdom_prompt, knowledge_base={})
results['wisdom'] = wisdom
# Stream wisdom to UI immediately
with wisdom_container:
st.markdown("**✅ Wisdom Extraction Complete**")
st.markdown(wisdom)
with pipeline_placeholder.container():
show_processing_pipeline(
current_step=1,
step_progress=100,
total_progress=33,
status_message="Wisdom extraction complete!",
processing_time=f"{time.time() - start_time:.1f}s"
)
# Step 3: Outline Creation
with pipeline_placeholder.container():
show_processing_pipeline(
current_step=2,
step_progress=0,
total_progress=33,
status_message="Creating structured outline...",
processing_time=f"{time.time() - start_time:.1f}s"
)
from core.content_generation import generate_outline
outline_prompt = get_prompt_for_step('outline', custom_prompts)
with pipeline_placeholder.container():
show_processing_pipeline(
current_step=2,
step_progress=50,
total_progress=42,
status_message="Structuring content hierarchy...",
processing_time=f"{time.time() - start_time:.1f}s"
)
outline = generate_outline(transcript, wisdom, custom_prompt=outline_prompt, knowledge_base={})
results['outline'] = outline
# Stream outline to UI immediately
with outline_container:
st.markdown("**✅ Outline Creation Complete**")
st.markdown(outline)
with pipeline_placeholder.container():
show_processing_pipeline(
current_step=2,
step_progress=100,
total_progress=50,
status_message="Outline creation complete!",
processing_time=f"{time.time() - start_time:.1f}s"
)
# Step 4: Article Generation
with pipeline_placeholder.container():
show_processing_pipeline(
current_step=3,
step_progress=0,
total_progress=50,
status_message="Generating comprehensive article...",
processing_time=f"{time.time() - start_time:.1f}s"
)
from core.content_generation import generate_article
article_prompt = get_prompt_for_step('article', custom_prompts)
selected_template = st.session_state.get('article_template')
if selected_template:
template_text = load_template(selected_template)
if template_text:
article_prompt = template_text + "\n" + article_prompt
with pipeline_placeholder.container():
show_processing_pipeline(
current_step=3,
step_progress=50,
total_progress=58,
status_message="Writing detailed article content...",
processing_time=f"{time.time() - start_time:.1f}s"
)
article = generate_article(transcript, wisdom, outline, custom_prompt=article_prompt, knowledge_base={})
results['article'] = article
# Stream article to UI immediately
with article_container:
st.markdown("**✅ Article Generation Complete**")
st.markdown(article)
with pipeline_placeholder.container():
show_processing_pipeline(
current_step=3,
step_progress=100,
total_progress=67,
status_message="Article generation complete!",
processing_time=f"{time.time() - start_time:.1f}s"
)
# Step 5: Social Content
with pipeline_placeholder.container():
show_processing_pipeline(
current_step=4,
step_progress=0,
total_progress=67,
status_message="Creating social media content...",
processing_time=f"{time.time() - start_time:.1f}s"
)
from core.content_generation import generate_social_content
social_prompt = get_prompt_for_step('social', custom_prompts)
with pipeline_placeholder.container():
show_processing_pipeline(
current_step=4,
step_progress=50,
total_progress=75,
status_message="Generating social media posts...",
processing_time=f"{time.time() - start_time:.1f}s"
)
social = generate_social_content(wisdom, outline, article, custom_prompt=social_prompt, knowledge_base={})
results['social_content'] = social
# Stream social content to UI immediately
with social_container:
st.markdown("**✅ Social Content Creation Complete**")
st.markdown(social)
with pipeline_placeholder.container():
show_processing_pipeline(
current_step=4,
step_progress=100,
total_progress=83,
status_message="Social content creation complete!",
processing_time=f"{time.time() - start_time:.1f}s"
)
# Step 6: Auto-publish to Notion
with pipeline_placeholder.container():
show_processing_pipeline(
current_step=5,
step_progress=0,
total_progress=83,
status_message="Publishing to Notion workspace...",
processing_time=f"{time.time() - start_time:.1f}s"
)
if os.getenv("NOTION_API_KEY") and os.getenv("NOTION_DATABASE_ID"):
# Generate AI title
ai_title = generate_ai_title(transcript)
with pipeline_placeholder.container():
show_processing_pipeline(
current_step=5,