import streamlit as st
import requests
import json
import streamlit.components.v1 as components
import os
# Import templates and icons from separate files
from templates import ARCHITECTURE_TEMPLATES, get_all_providers, get_template
from service_icons import SERVICE_ICONS, get_icon_url, map_service_to_icon
# Page Configuration
st.set_page_config(
page_title="ArchViz AI Pro - Draw.io Style Icons",
page_icon="🏗️",
layout="wide"
)
# API Configuration
OPENROUTER_API_KEY = os.environ.get("OPENROUTER_API_KEY")
# UI Styling
st.markdown("""
🏗️ ArchViz AI Pro Pro EditionDraw.io Icons
Enterprise Architecture Visualization with Official Cloud Service Icons
""", unsafe_allow_html=True)
# Sidebar Configuration
st.sidebar.title("📚 Cloud Architecture Library")
st.sidebar.markdown("Select from professional architecture templates:")
selected_provider = st.sidebar.selectbox(
"Cloud Provider:",
["None"] + get_all_providers()
)
if selected_provider != "None":
templates = ARCHITECTURE_TEMPLATES[selected_provider]
selected_template = st.sidebar.selectbox(
f"{selected_provider} Templates:",
list(templates.keys())
)
if st.sidebar.button("Load Template", use_container_width=True):
template_data = templates[selected_template]
st.session_state['template_text'] = template_data["description"]
st.session_state['template_services'] = template_data.get("services", [])
st.sidebar.markdown("---")
st.sidebar.markdown(f"**Template: {selected_template}**")
template_info = templates[selected_template]
st.sidebar.info(template_info["description"][:200] + "...")
st.sidebar.markdown(f"**Use Case:** {template_info['use_case']}")
if "services" in template_info:
st.sidebar.markdown(f"**Services:** {', '.join(template_info['services'])}")
st.sidebar.markdown("---")
st.sidebar.markdown("### ✨ Pro Features")
st.sidebar.markdown("""
**🎨 Draw.io-Style Icons:**
- ✅ Official AWS Architecture Icons
- ✅ Official GCP Service Icons
- ✅ Official Azure Service Icons
- ✅ 100+ Service-Specific Icons
**💼 Enterprise Features:**
- ✅ Edit Generated Diagrams
- ✅ High-Quality PNG Export
- ✅ Fullscreen Presentation Mode
- ✅ Professional Templates
**Perfect for:**
- Solution Architecture
- RFP Responses
- Client Presentations
- Technical Documentation
""")
# Main Layout
col1, col2 = st.columns([1, 1.5])
with col1:
st.subheader("📝 Architecture Description")
default_text = st.session_state.get('template_text', '')
prompt_text = st.text_area(
"Describe your cloud architecture:",
value=default_text,
height=200,
placeholder="Example: Mobile app connects to AWS API Gateway, which routes to Lambda functions..."
)
st.info("💡 **Pro Tip:** Mention specific service names (Lambda, Cloud Run, Functions App) to get official cloud icons!")
col_gen, col_edit = st.columns(2)
with col_gen:
generate_btn = st.button("✨ Generate Diagram", type="primary", use_container_width=True)
with col_edit:
if 'mermaid_code' in st.session_state:
edit_mode = st.button("✏️ Edit Code", use_container_width=True)
if edit_mode:
st.session_state['show_editor'] = not st.session_state.get('show_editor', False)
# Show editor if requested
if st.session_state.get('show_editor', False) and 'mermaid_code' in st.session_state:
st.markdown("---")
st.subheader("🛠️ Edit Diagram Code")
edited_code = st.text_area(
"Modify the Mermaid code:",
value=st.session_state['mermaid_code'],
height=250,
key="editor",
help="Edit the diagram structure, labels, or styling"
)
col_apply, col_cancel = st.columns(2)
with col_apply:
if st.button("✅ Apply Changes", use_container_width=True):
st.session_state['mermaid_code'] = edited_code
st.session_state['show_editor'] = False
st.rerun()
with col_cancel:
if st.button("❌ Cancel", use_container_width=True):
st.session_state['show_editor'] = False
st.rerun()
# Display detected services
if 'template_services' in st.session_state and st.session_state['template_services']:
st.markdown("---")
st.markdown("**📦 Template Services:**")
services_html = ""
for service in st.session_state['template_services']:
provider, icon_url = map_service_to_icon(service)
if icon_url:
services_html += f'