-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.py
More file actions
124 lines (101 loc) · 3.99 KB
/
app.py
File metadata and controls
124 lines (101 loc) · 3.99 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
import streamlit as st
import pypandoc
import tempfile
import os
from src.nexus_ai.crew import NexusAi
# --- Page Configuration ---
st.set_page_config(
page_title="NexusAI Strategy Generator",
layout="wide",
)
# --- App Styling ---
st.markdown("""
<style>
.stButton>button {
width: 100%;
}
.stSpinner {
text-align: center;
}
</style>
""", unsafe_allow_html=True)
# --- App Header ---
st.title("NexusAI")
st.markdown("### Your AI-Powered Strategic Proposal Generator")
st.markdown("---")
# --- Main Content Area ---
# Initialize session state for report and company name
if "report" not in st.session_state:
st.session_state.report = None
if "company" not in st.session_state:
st.session_state.company = ""
# Create a two-column layout
col1, col2 = st.columns([1, 2])
# --- Column 1: Configuration and Control ---
with col1:
st.header("Configuration")
company = st.text_input("Enter Company Name", placeholder="e.g., Nike")
industry = st.text_input("Enter Industry", placeholder="e.g., Apparel")
run_button = st.button("Generate Proposal", type="primary", use_container_width=True)
st.markdown("---")
st.markdown("""
<div style="font-size: 0.9em;">
<strong>Instructions:</strong>
<ol>
<li>Enter the name of the company and its industry.</li>
<li>Click "Generate Proposal".</li>
<li>The AI crew will analyze the company and generate a strategic report in the panel to the right.</li>
</ol>
</div>
""", unsafe_allow_html=True)
# --- Column 2: Output and Progress ---
with col2:
if run_button:
if not company or not industry:
st.error("Please provide both a company and an industry to proceed.")
else:
st.session_state.report = None
with st.spinner("Generating AI Strategy Proposal..."):
try:
inputs = {'company': company, 'industry': industry}
nexus_ai_crew = NexusAi().crew()
crew_result = nexus_ai_crew.kickoff(inputs=inputs)
st.session_state.report = str(crew_result)
st.session_state.company = company
except Exception as e:
st.error(f"An unexpected error occurred: {e}")
if st.session_state.report:
st.header(f"AI Strategy Proposal: {st.session_state.company}")
tab1, tab2 = st.tabs(["Final Report", "Raw Markdown"])
with tab1:
st.markdown(st.session_state.report)
with tab2:
st.code(st.session_state.report, language="markdown")
st.markdown("---")
st.header("Actions")
try:
with tempfile.NamedTemporaryFile(delete=False, suffix=".docx") as temp_docx:
pypandoc.convert_text(
st.session_state.report,
'docx',
format='md',
outputfile=temp_docx.name,
extra_args=['--reference-doc=reference.docx']
)
with open(temp_docx.name, "rb") as f:
docx_bytes = f.read()
st.download_button(
label="Download as .docx",
data=docx_bytes,
file_name=f"AI_Proposal_for_{st.session_state.company}.docx",
mime="application/vnd.openxmlformats-officedocument.wordprocessingml.document",
use_container_width=True
)
os.unlink(temp_docx.name)
except FileNotFoundError:
st.error("Could not generate DOCX. Please ensure 'reference.docx' is in the project's root directory.")
except Exception as e:
st.error(f"Could not generate DOCX. Please ensure Pandoc is installed. Error: {e}")
else:
if not run_button:
st.info("Enter company details on the left and click 'Generate Proposal' to begin.")