Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -60,44 +60,95 @@ def run_market_research(topic: str, progress_container):
|
|
| 60 |
else:
|
| 61 |
raw_text = str(result)
|
| 62 |
|
| 63 |
-
# Process the raw text into
|
| 64 |
sections = raw_text.split('===')
|
| 65 |
-
processed_report = {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 66 |
|
|
|
|
| 67 |
for section in sections:
|
| 68 |
if not section.strip():
|
| 69 |
continue
|
| 70 |
|
| 71 |
-
# Split into section name and content
|
| 72 |
parts = section.strip().split('\n', 1)
|
| 73 |
if len(parts) == 2:
|
| 74 |
section_name, content = parts
|
| 75 |
-
|
| 76 |
-
|
| 77 |
-
|
| 78 |
-
|
| 79 |
-
|
| 80 |
-
|
| 81 |
-
|
| 82 |
-
|
| 83 |
-
|
| 84 |
-
|
| 85 |
-
|
| 86 |
-
|
| 87 |
-
|
| 88 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 89 |
|
| 90 |
# Update final progress
|
| 91 |
update_progress(progress_container, 100, "Report completed!")
|
| 92 |
st.success("✨ Market research report generated successfully!")
|
| 93 |
|
| 94 |
-
return
|
| 95 |
|
| 96 |
except Exception as e:
|
| 97 |
st.error(f"Error during research: {str(e)}")
|
| 98 |
print(f"Full error details: {str(e)}") # For debugging
|
| 99 |
-
return
|
| 100 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 101 |
def main():
|
| 102 |
st.title("🤖 AI Market Research Generator")
|
| 103 |
|
|
@@ -152,120 +203,130 @@ def main():
|
|
| 152 |
report = st.session_state.current_report
|
| 153 |
topic = st.session_state.current_topic
|
| 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 |
## Executive Summary
|
| 223 |
-
{report
|
| 224 |
|
| 225 |
### Market Highlights
|
| 226 |
-
{report
|
| 227 |
|
| 228 |
### Strategic Implications
|
| 229 |
-
{report
|
| 230 |
|
| 231 |
### Key Recommendations
|
| 232 |
-
{report
|
| 233 |
|
| 234 |
-
##
|
| 235 |
|
| 236 |
### Market Overview
|
| 237 |
-
{report
|
| 238 |
|
| 239 |
### Industry Dynamics
|
| 240 |
-
{report
|
| 241 |
|
| 242 |
### Competitive Landscape
|
| 243 |
-
{report
|
| 244 |
|
| 245 |
### Strategic Analysis
|
| 246 |
-
{report
|
| 247 |
|
| 248 |
## Future Outlook
|
| 249 |
-
{report
|
| 250 |
-
|
| 251 |
-
## Key Metrics
|
| 252 |
-
- Market Size: {report.get('metrics', {}).get('market_size', 'N/A')}
|
| 253 |
-
- Growth Rate: {report.get('metrics', {}).get('growth_rate', 'N/A')}
|
| 254 |
-
- Market Share: {report.get('metrics', {}).get('market_shares', 'N/A')}
|
| 255 |
|
| 256 |
## Sources
|
| 257 |
-
{chr(10).join([f"• {source}" for source in report
|
| 258 |
-
|
| 259 |
-
## Appendices
|
| 260 |
-
{report.get('appendices', '')}
|
| 261 |
""",
|
| 262 |
-
|
| 263 |
-
|
| 264 |
-
|
| 265 |
-
|
|
|
|
| 266 |
except Exception as e:
|
| 267 |
st.error(f"Error displaying report: {str(e)}")
|
| 268 |
st.write("Raw report data:", report) # Debug information
|
|
|
|
| 269 |
|
| 270 |
if __name__ == "__main__":
|
| 271 |
main()
|
|
|
|
| 60 |
else:
|
| 61 |
raw_text = str(result)
|
| 62 |
|
| 63 |
+
# Process the raw text into sections
|
| 64 |
sections = raw_text.split('===')
|
| 65 |
+
processed_report = {
|
| 66 |
+
'exec_summary': {
|
| 67 |
+
'summary': '',
|
| 68 |
+
'market_highlights': '',
|
| 69 |
+
'strategic_implications': '',
|
| 70 |
+
'recommendations': ''
|
| 71 |
+
},
|
| 72 |
+
'market_analysis': {
|
| 73 |
+
'overview': '',
|
| 74 |
+
'dynamics': '',
|
| 75 |
+
'competitive_landscape': '',
|
| 76 |
+
'strategic_analysis': ''
|
| 77 |
+
},
|
| 78 |
+
'future_outlook': '',
|
| 79 |
+
'appendices': '',
|
| 80 |
+
'sources': []
|
| 81 |
+
}
|
| 82 |
|
| 83 |
+
# Process each section
|
| 84 |
for section in sections:
|
| 85 |
if not section.strip():
|
| 86 |
continue
|
| 87 |
|
|
|
|
| 88 |
parts = section.strip().split('\n', 1)
|
| 89 |
if len(parts) == 2:
|
| 90 |
section_name, content = parts
|
| 91 |
+
section_name = section_name.strip().upper()
|
| 92 |
+
content = content.strip()
|
| 93 |
+
|
| 94 |
+
if section_name == 'EXECUTIVE SUMMARY':
|
| 95 |
+
# Process executive summary
|
| 96 |
+
processed_report['exec_summary']['summary'] = content
|
| 97 |
+
# Extract main points for highlights
|
| 98 |
+
if '##' in content:
|
| 99 |
+
highlights = content.split('##')[1:]
|
| 100 |
+
processed_report['exec_summary']['market_highlights'] = highlights[0] if highlights else ''
|
| 101 |
+
processed_report['exec_summary']['strategic_implications'] = highlights[1] if len(highlights) > 1 else ''
|
| 102 |
+
processed_report['exec_summary']['recommendations'] = highlights[2] if len(highlights) > 2 else ''
|
| 103 |
+
|
| 104 |
+
elif section_name == 'MARKET ANALYSIS':
|
| 105 |
+
# Process market analysis section
|
| 106 |
+
subsections = content.split('##')
|
| 107 |
+
processed_report['market_analysis']['overview'] = subsections[0]
|
| 108 |
+
for subsection in subsections[1:]:
|
| 109 |
+
if 'dynamics' in subsection.lower():
|
| 110 |
+
processed_report['market_analysis']['dynamics'] = subsection
|
| 111 |
+
elif 'competitive' in subsection.lower():
|
| 112 |
+
processed_report['market_analysis']['competitive_landscape'] = subsection
|
| 113 |
+
elif 'strategic' in subsection.lower():
|
| 114 |
+
processed_report['market_analysis']['strategic_analysis'] = subsection
|
| 115 |
+
|
| 116 |
+
elif section_name == 'FUTURE OUTLOOK':
|
| 117 |
+
processed_report['future_outlook'] = content
|
| 118 |
+
|
| 119 |
+
elif section_name == 'APPENDICES':
|
| 120 |
+
processed_report['appendices'] = content
|
| 121 |
+
# Extract sources from appendices
|
| 122 |
+
sources = [line.strip() for line in content.split('\n')
|
| 123 |
+
if line.strip().startswith('-') or line.strip().startswith('•')]
|
| 124 |
+
processed_report['sources'] = sources
|
| 125 |
|
| 126 |
# Update final progress
|
| 127 |
update_progress(progress_container, 100, "Report completed!")
|
| 128 |
st.success("✨ Market research report generated successfully!")
|
| 129 |
|
| 130 |
+
return processed_report
|
| 131 |
|
| 132 |
except Exception as e:
|
| 133 |
st.error(f"Error during research: {str(e)}")
|
| 134 |
print(f"Full error details: {str(e)}") # For debugging
|
| 135 |
+
return {
|
| 136 |
+
'exec_summary': {
|
| 137 |
+
'summary': 'Error processing report',
|
| 138 |
+
'market_highlights': '',
|
| 139 |
+
'strategic_implications': '',
|
| 140 |
+
'recommendations': ''
|
| 141 |
+
},
|
| 142 |
+
'market_analysis': {
|
| 143 |
+
'overview': str(raw_text) if 'raw_text' in locals() else 'Error processing analysis',
|
| 144 |
+
'dynamics': '',
|
| 145 |
+
'competitive_landscape': '',
|
| 146 |
+
'strategic_analysis': ''
|
| 147 |
+
},
|
| 148 |
+
'future_outlook': '',
|
| 149 |
+
'appendices': '',
|
| 150 |
+
'sources': []
|
| 151 |
+
}
|
| 152 |
def main():
|
| 153 |
st.title("🤖 AI Market Research Generator")
|
| 154 |
|
|
|
|
| 203 |
report = st.session_state.current_report
|
| 204 |
topic = st.session_state.current_topic
|
| 205 |
|
| 206 |
+
st.markdown("""
|
| 207 |
+
<div class="report-container">
|
| 208 |
+
<!-- AI Disclaimer -->
|
| 209 |
+
<div class="disclaimer">
|
| 210 |
+
⚠️ This report was generated using AI. While we strive for accuracy,
|
| 211 |
+
please verify critical information independently before making decisions.
|
| 212 |
+
</div>
|
| 213 |
+
|
| 214 |
+
<!-- Report Title -->
|
| 215 |
+
<h1 class="section-heading">📊 Market Research Report: {}</h1>
|
| 216 |
+
|
| 217 |
+
<!-- Executive Summary -->
|
| 218 |
+
<div class="report-section executive-summary">
|
| 219 |
+
<h2 class="section-heading">Executive Summary</h2>
|
| 220 |
+
<div class="content-block">{}</div>
|
| 221 |
+
|
| 222 |
+
<h3 class="subsection-heading">Key Market Highlights</h3>
|
| 223 |
+
<div class="content-block">{}</div>
|
| 224 |
+
|
| 225 |
+
<h3 class="subsection-heading">Strategic Implications</h3>
|
| 226 |
+
<div class="content-block">{}</div>
|
| 227 |
+
|
| 228 |
+
<h3 class="subsection-heading">Recommendations</h3>
|
| 229 |
+
<div class="content-block">{}</div>
|
| 230 |
+
</div>
|
| 231 |
+
|
| 232 |
+
<!-- Market Analysis -->
|
| 233 |
+
<div class="report-section market-analysis">
|
| 234 |
+
<h2 class="section-heading">Market Analysis</h2>
|
| 235 |
+
|
| 236 |
+
<h3 class="subsection-heading">Market Overview</h3>
|
| 237 |
+
<div class="content-block">{}</div>
|
| 238 |
+
|
| 239 |
+
<h3 class="subsection-heading">Industry Dynamics</h3>
|
| 240 |
+
<div class="content-block">{}</div>
|
| 241 |
+
|
| 242 |
+
<h3 class="subsection-heading">Competitive Landscape</h3>
|
| 243 |
+
<div class="content-block">{}</div>
|
| 244 |
+
|
| 245 |
+
<h3 class="subsection-heading">Strategic Analysis</h3>
|
| 246 |
+
<div class="content-block">{}</div>
|
| 247 |
+
</div>
|
| 248 |
+
|
| 249 |
+
<!-- Future Outlook -->
|
| 250 |
+
<div class="report-section future-outlook">
|
| 251 |
+
<h2 class="section-heading">Future Outlook</h2>
|
| 252 |
+
<div class="content-block">{}</div>
|
| 253 |
+
</div>
|
| 254 |
+
|
| 255 |
+
<!-- Sources -->
|
| 256 |
+
<div class="report-section sources-section">
|
| 257 |
+
<h2 class="section-heading">Sources</h2>
|
| 258 |
+
{}
|
| 259 |
+
</div>
|
| 260 |
+
</div>
|
| 261 |
+
""".format(
|
| 262 |
+
topic,
|
| 263 |
+
report['exec_summary']['summary'],
|
| 264 |
+
report['exec_summary']['market_highlights'],
|
| 265 |
+
report['exec_summary']['strategic_implications'],
|
| 266 |
+
report['exec_summary']['recommendations'],
|
| 267 |
+
report['market_analysis']['overview'],
|
| 268 |
+
report['market_analysis']['dynamics'],
|
| 269 |
+
report['market_analysis']['competitive_landscape'],
|
| 270 |
+
report['market_analysis']['strategic_analysis'],
|
| 271 |
+
report['future_outlook'],
|
| 272 |
+
'\n'.join([f'<div class="source-item">• {source}</div>' for source in report['sources']])
|
| 273 |
+
), unsafe_allow_html=True)
|
| 274 |
+
|
| 275 |
+
# Download button with custom styling
|
| 276 |
+
st.markdown("""
|
| 277 |
+
<div style="text-align: center; margin-top: 30px;">
|
| 278 |
+
<button class="download-button" onclick="alert('Use the Streamlit download button below')">
|
| 279 |
+
📥 Download Complete Report
|
| 280 |
+
</button>
|
| 281 |
+
</div>
|
| 282 |
+
""", unsafe_allow_html=True)
|
| 283 |
+
|
| 284 |
+
# Actual download functionality (hidden but functional)
|
| 285 |
+
st.download_button(
|
| 286 |
+
"Download Report",
|
| 287 |
+
data=f"""# Market Research Report: {topic}
|
| 288 |
|
| 289 |
## Executive Summary
|
| 290 |
+
{report['exec_summary']['summary']}
|
| 291 |
|
| 292 |
### Market Highlights
|
| 293 |
+
{report['exec_summary']['market_highlights']}
|
| 294 |
|
| 295 |
### Strategic Implications
|
| 296 |
+
{report['exec_summary']['strategic_implications']}
|
| 297 |
|
| 298 |
### Key Recommendations
|
| 299 |
+
{report['exec_summary']['recommendations']}
|
| 300 |
|
| 301 |
+
## Market Analysis
|
| 302 |
|
| 303 |
### Market Overview
|
| 304 |
+
{report['market_analysis']['overview']}
|
| 305 |
|
| 306 |
### Industry Dynamics
|
| 307 |
+
{report['market_analysis']['dynamics']}
|
| 308 |
|
| 309 |
### Competitive Landscape
|
| 310 |
+
{report['market_analysis']['competitive_landscape']}
|
| 311 |
|
| 312 |
### Strategic Analysis
|
| 313 |
+
{report['market_analysis']['strategic_analysis']}
|
| 314 |
|
| 315 |
## Future Outlook
|
| 316 |
+
{report['future_outlook']}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 317 |
|
| 318 |
## Sources
|
| 319 |
+
{chr(10).join([f"• {source}" for source in report['sources']])}
|
|
|
|
|
|
|
|
|
|
| 320 |
""",
|
| 321 |
+
file_name=f"{topic.lower().replace(' ', '_')}_market_research.md",
|
| 322 |
+
mime="text/markdown",
|
| 323 |
+
key='download_button',
|
| 324 |
+
help="Click to download the complete report",
|
| 325 |
+
)
|
| 326 |
except Exception as e:
|
| 327 |
st.error(f"Error displaying report: {str(e)}")
|
| 328 |
st.write("Raw report data:", report) # Debug information
|
| 329 |
+
|
| 330 |
|
| 331 |
if __name__ == "__main__":
|
| 332 |
main()
|