Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,154 +1,4 @@
|
|
| 1 |
-
|
| 2 |
-
st.header("Multi-Persona Thinking Processes")
|
| 3 |
-
|
| 4 |
-
if not st.session_state.thinking_logs:
|
| 5 |
-
st.info("No thinking process to display yet. Start writing a chapter to see the personas at work.")
|
| 6 |
-
else:
|
| 7 |
-
# Display the thinking logs
|
| 8 |
-
for i, log in enumerate(st.session_state.thinking_logs):
|
| 9 |
-
step_num = i + 1
|
| 10 |
-
timestamp = log.get("timestamp", "")
|
| 11 |
-
timestamp_str = datetime.fromtimestamp(timestamp).strftime('%Y-%m-%d %H:%M:%S') if timestamp else ""
|
| 12 |
-
|
| 13 |
-
with st.expander(f"Step {step_num}: {log.get('agent', 'Unknown Agent')} {timestamp_str}", expanded=i==0):
|
| 14 |
-
st.markdown(log.get("thought", "No thought recorded"))
|
| 15 |
-
|
| 16 |
-
# Clear logs button
|
| 17 |
-
if st.button("Clear Thinking Logs"):
|
| 18 |
-
st.session_state.thinking_logs = []
|
| 19 |
-
save_thinking_logs()
|
| 20 |
-
st.success("Thinking logs cleared.")
|
| 21 |
-
st.experimental_rerun()
|
| 22 |
-
|
| 23 |
-
# Sidebar
|
| 24 |
-
with st.sidebar:
|
| 25 |
-
# About the app
|
| 26 |
-
with st.expander("📖 About self.api Book Writer", expanded=False):
|
| 27 |
-
st.markdown("""
|
| 28 |
-
# About self.api Book Writer
|
| 29 |
-
|
| 30 |
-
This application helps you write a book that uses API metaphors to explain spiritual concepts. It employs a multi-persona reasoning approach, where different specialist personas collaborate on each chapter.
|
| 31 |
-
|
| 32 |
-
## Key Features
|
| 33 |
-
|
| 34 |
-
- **Multi-Persona Writing**: Each chapter benefits from diverse specialist perspectives
|
| 35 |
-
- **Research Integration**: Web research can be incorporated into chapter development
|
| 36 |
-
- **LangGraph Workflow**: Orchestrated agent collaboration for chapter creation
|
| 37 |
-
- **Complete Book Management**: From outline to final export
|
| 38 |
-
- **Transparency**: See the thinking process behind each contribution
|
| 39 |
-
|
| 40 |
-
## Workflow
|
| 41 |
-
|
| 42 |
-
1. Setup your book outline
|
| 43 |
-
2. Select the appropriate personas for each chapter
|
| 44 |
-
3. Generate persona contributions
|
| 45 |
-
4. Synthesize the final chapter
|
| 46 |
-
5. Export your completed book
|
| 47 |
-
|
| 48 |
-
Built with Streamlit, LangGraph, and Claude 3.7.
|
| 49 |
-
""")
|
| 50 |
-
|
| 51 |
-
# Persona Library
|
| 52 |
-
with st.expander("👤 Persona Library", expanded=False):
|
| 53 |
-
st.subheader("Available Personas")
|
| 54 |
-
|
| 55 |
-
# Display personas by category
|
| 56 |
-
for category, persona_ids in st.session_state.persona_categories.items():
|
| 57 |
-
show_category = st.checkbox(f"{category} ({len(persona_ids)} personas)", key=f"cat_{category}")
|
| 58 |
-
if show_category:
|
| 59 |
-
for persona_id in persona_ids:
|
| 60 |
-
if persona_id in st.session_state.persona_library:
|
| 61 |
-
persona = st.session_state.persona_library[persona_id]
|
| 62 |
-
with st.expander(f"{persona['name']}", expanded=False):
|
| 63 |
-
st.write(f"**Description:** {persona['description']}")
|
| 64 |
-
|
| 65 |
-
# Show system prompt if desired
|
| 66 |
-
if st.checkbox("Show System Prompt", key=f"show_prompt_{persona_id}"):
|
| 67 |
-
st.text_area(
|
| 68 |
-
"System Prompt",
|
| 69 |
-
value=persona['system_prompt'],
|
| 70 |
-
height=200,
|
| 71 |
-
key=f"prompt_{persona_id}",
|
| 72 |
-
disabled=True
|
| 73 |
-
)
|
| 74 |
-
|
| 75 |
-
# Save/Load Book Data
|
| 76 |
-
with st.expander("💾 Save/Load Book Data", expanded=False):
|
| 77 |
-
st.subheader("Save Book Data")
|
| 78 |
-
|
| 79 |
-
# Export book data
|
| 80 |
-
book_json = json.dumps(st.session_state.book_data, indent=2)
|
| 81 |
-
st.download_button(
|
| 82 |
-
"Download Book Project Data",
|
| 83 |
-
book_json,
|
| 84 |
-
file_name=f"{st.session_state.book_data['title']}_project.json",
|
| 85 |
-
mime="application/json"
|
| 86 |
-
)
|
| 87 |
-
|
| 88 |
-
st.subheader("Load Book Data")
|
| 89 |
-
|
| 90 |
-
uploaded_book = st.file_uploader("Upload Book Project Data", type=["json"])
|
| 91 |
-
if uploaded_book:
|
| 92 |
-
try:
|
| 93 |
-
book_data = json.loads(uploaded_book.read().decode())
|
| 94 |
-
if st.button("Load Book Project"):
|
| 95 |
-
st.session_state.book_data = book_data
|
| 96 |
-
save_book_data()
|
| 97 |
-
st.success("Book project loaded successfully!")
|
| 98 |
-
st.experimental_rerun()
|
| 99 |
-
except Exception as e:
|
| 100 |
-
st.error(f"Error loading book data: {str(e)}")
|
| 101 |
-
|
| 102 |
-
# Settings
|
| 103 |
-
st.header("Settings")
|
| 104 |
-
|
| 105 |
-
# API Keys
|
| 106 |
-
with st.expander("API Keys", expanded=False):
|
| 107 |
-
anthropic_api_key = st.text_input(
|
| 108 |
-
"Anthropic API Key",
|
| 109 |
-
type="password",
|
| 110 |
-
value=st.session_state.get("anthropic_api_key", ""),
|
| 111 |
-
help="Required for Claude 3.7 access"
|
| 112 |
-
)
|
| 113 |
-
if anthropic_api_key:
|
| 114 |
-
st.session_state.anthropic_api_key = anthropic_api_key
|
| 115 |
-
os.environ["ANTHROPIC_API_KEY"] = anthropic_api_key
|
| 116 |
-
|
| 117 |
-
tavily_api_key = st.text_input(
|
| 118 |
-
"Tavily API Key",
|
| 119 |
-
type="password",
|
| 120 |
-
value=st.session_state.get("tavily_api_key", ""),
|
| 121 |
-
help="Required for web research capabilities"
|
| 122 |
-
)
|
| 123 |
-
if tavily_api_key:
|
| 124 |
-
st.session_state.tavily_api_key = tavily_api_key
|
| 125 |
-
os.environ["TAVILY_API_KEY"] = tavily_api_key
|
| 126 |
-
|
| 127 |
-
# Test connection
|
| 128 |
-
if st.button("Test Connection"):
|
| 129 |
-
client = get_claude_client()
|
| 130 |
-
if client:
|
| 131 |
-
try:
|
| 132 |
-
response = client.messages.create(
|
| 133 |
-
model="claude-3-7-sonnet-20250219",
|
| 134 |
-
messages=[{"role": "user", "content": "Hello"}],
|
| 135 |
-
max_tokens=10
|
| 136 |
-
)
|
| 137 |
-
st.success("Claude connection successful!")
|
| 138 |
-
except Exception as e:
|
| 139 |
-
st.error(f"Claude connection failed: {str(e)}")
|
| 140 |
-
|
| 141 |
-
# Test Tavily if API key is provided
|
| 142 |
-
if st.session_state.get("tavily_api_key"):
|
| 143 |
-
try:
|
| 144 |
-
research_agent = get_research_agent()
|
| 145 |
-
if research_agent:
|
| 146 |
-
st.success("Tavily research connection successful!")
|
| 147 |
-
except Exception as e:
|
| 148 |
-
st.error(f"Tavily research connection failed: {str(e)}")
|
| 149 |
-
|
| 150 |
-
# Check for autosave
|
| 151 |
-
check_autosave()import streamlit as st
|
| 152 |
import os
|
| 153 |
import json
|
| 154 |
import pandas as pd
|
|
|
|
| 1 |
+
import streamlit as st
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 2 |
import os
|
| 3 |
import json
|
| 4 |
import pandas as pd
|