Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -56,28 +56,28 @@ def run_market_research(topic: str, progress_container):
|
|
| 56 |
|
| 57 |
def main():
|
| 58 |
st.title("🤖 AI Market Research Generator")
|
| 59 |
-
|
| 60 |
# Get API keys
|
| 61 |
serper_key, openai_key = get_api_keys()
|
| 62 |
-
|
| 63 |
if not serper_key or not openai_key:
|
| 64 |
st.error("Failed to load required API keys. Please check your Hugging Face Space secrets.")
|
| 65 |
return
|
| 66 |
-
|
| 67 |
# Initialize session states
|
| 68 |
if 'generating' not in st.session_state:
|
| 69 |
st.session_state.generating = False
|
| 70 |
-
|
| 71 |
# Create tabs
|
| 72 |
tab1, tab2 = st.tabs(["Generate Report", "View Reports"])
|
| 73 |
-
|
| 74 |
with tab1:
|
| 75 |
st.subheader("Enter Research Topic")
|
| 76 |
topic = st.text_input(
|
| 77 |
"What market would you like to research?",
|
| 78 |
placeholder="e.g., Electric Vehicles Market"
|
| 79 |
)
|
| 80 |
-
|
| 81 |
if st.session_state.generating:
|
| 82 |
st.button("Generating Report...", disabled=True)
|
| 83 |
else:
|
|
@@ -86,79 +86,142 @@ def main():
|
|
| 86 |
st.error("Please enter a research topic")
|
| 87 |
else:
|
| 88 |
st.session_state.generating = True
|
| 89 |
-
|
| 90 |
# Create progress container
|
| 91 |
progress_container = st.container()
|
| 92 |
-
|
| 93 |
try:
|
| 94 |
with st.spinner("Generating comprehensive market research report..."):
|
| 95 |
result = run_market_research(topic, progress_container)
|
| 96 |
-
|
| 97 |
-
|
| 98 |
-
|
| 99 |
-
|
| 100 |
-
|
| 101 |
except Exception as e:
|
| 102 |
st.error(f"Error generating report: {str(e)}")
|
| 103 |
finally:
|
| 104 |
st.session_state.generating = False
|
| 105 |
-
|
| 106 |
with tab2:
|
| 107 |
if 'current_report' in st.session_state:
|
| 108 |
report = st.session_state.current_report
|
| 109 |
topic = st.session_state.current_topic
|
| 110 |
-
|
| 111 |
# Display AI Disclaimer
|
| 112 |
st.info("⚠️ This report was generated using AI. Please verify critical information independently.")
|
| 113 |
-
|
| 114 |
try:
|
| 115 |
-
# Executive Summary
|
| 116 |
-
st.header("
|
| 117 |
-
|
| 118 |
-
|
| 119 |
-
|
| 120 |
-
|
| 121 |
-
|
| 122 |
-
|
| 123 |
-
|
| 124 |
-
|
| 125 |
-
|
| 126 |
-
|
| 127 |
-
|
| 128 |
-
|
| 129 |
-
|
| 130 |
-
|
| 131 |
-
|
| 132 |
-
|
| 133 |
-
st.
|
| 134 |
-
|
| 135 |
-
|
| 136 |
-
|
| 137 |
-
|
| 138 |
-
|
| 139 |
-
|
| 140 |
-
|
| 141 |
-
|
| 142 |
-
|
| 143 |
-
|
| 144 |
-
|
| 145 |
-
|
| 146 |
-
|
| 147 |
-
|
| 148 |
-
|
| 149 |
-
|
| 150 |
-
|
| 151 |
-
|
| 152 |
-
|
| 153 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 154 |
st.download_button(
|
| 155 |
-
"Download Report",
|
| 156 |
-
data=
|
| 157 |
-
|
| 158 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 159 |
)
|
| 160 |
-
|
| 161 |
except Exception as e:
|
| 162 |
st.error(f"Error displaying report: {str(e)}")
|
|
|
|
|
|
|
| 163 |
if __name__ == "__main__":
|
| 164 |
main()
|
|
|
|
| 56 |
|
| 57 |
def main():
|
| 58 |
st.title("🤖 AI Market Research Generator")
|
| 59 |
+
|
| 60 |
# Get API keys
|
| 61 |
serper_key, openai_key = get_api_keys()
|
| 62 |
+
|
| 63 |
if not serper_key or not openai_key:
|
| 64 |
st.error("Failed to load required API keys. Please check your Hugging Face Space secrets.")
|
| 65 |
return
|
| 66 |
+
|
| 67 |
# Initialize session states
|
| 68 |
if 'generating' not in st.session_state:
|
| 69 |
st.session_state.generating = False
|
| 70 |
+
|
| 71 |
# Create tabs
|
| 72 |
tab1, tab2 = st.tabs(["Generate Report", "View Reports"])
|
| 73 |
+
|
| 74 |
with tab1:
|
| 75 |
st.subheader("Enter Research Topic")
|
| 76 |
topic = st.text_input(
|
| 77 |
"What market would you like to research?",
|
| 78 |
placeholder="e.g., Electric Vehicles Market"
|
| 79 |
)
|
| 80 |
+
|
| 81 |
if st.session_state.generating:
|
| 82 |
st.button("Generating Report...", disabled=True)
|
| 83 |
else:
|
|
|
|
| 86 |
st.error("Please enter a research topic")
|
| 87 |
else:
|
| 88 |
st.session_state.generating = True
|
| 89 |
+
|
| 90 |
# Create progress container
|
| 91 |
progress_container = st.container()
|
| 92 |
+
|
| 93 |
try:
|
| 94 |
with st.spinner("Generating comprehensive market research report..."):
|
| 95 |
result = run_market_research(topic, progress_container)
|
| 96 |
+
|
| 97 |
+
if result:
|
| 98 |
+
st.session_state.current_report = result
|
| 99 |
+
st.session_state.current_topic = topic
|
| 100 |
+
st.success("Report generated successfully! View it in the Reports tab.")
|
| 101 |
except Exception as e:
|
| 102 |
st.error(f"Error generating report: {str(e)}")
|
| 103 |
finally:
|
| 104 |
st.session_state.generating = False
|
| 105 |
+
|
| 106 |
with tab2:
|
| 107 |
if 'current_report' in st.session_state:
|
| 108 |
report = st.session_state.current_report
|
| 109 |
topic = st.session_state.current_topic
|
| 110 |
+
|
| 111 |
# Display AI Disclaimer
|
| 112 |
st.info("⚠️ This report was generated using AI. Please verify critical information independently.")
|
| 113 |
+
|
| 114 |
try:
|
| 115 |
+
# Executive Summary Section
|
| 116 |
+
st.header(f"📊 Market Research Report: {topic}")
|
| 117 |
+
|
| 118 |
+
with st.expander("Executive Summary", expanded=True):
|
| 119 |
+
st.subheader("Key Findings")
|
| 120 |
+
st.write(report.get('exec_summary', {}).get('summary', ''))
|
| 121 |
+
|
| 122 |
+
st.subheader("Market Highlights")
|
| 123 |
+
st.write(report.get('exec_summary', {}).get('market_highlights', ''))
|
| 124 |
+
|
| 125 |
+
st.subheader("Strategic Implications")
|
| 126 |
+
st.write(report.get('exec_summary', {}).get('strategic_implications', ''))
|
| 127 |
+
|
| 128 |
+
st.subheader("Key Recommendations")
|
| 129 |
+
st.write(report.get('exec_summary', {}).get('recommendations', ''))
|
| 130 |
+
|
| 131 |
+
# Market Analysis Section
|
| 132 |
+
with st.expander("Detailed Market Analysis", expanded=False):
|
| 133 |
+
st.subheader("Market Overview")
|
| 134 |
+
st.write(report.get('market_analysis', {}).get('overview', ''))
|
| 135 |
+
|
| 136 |
+
st.subheader("Industry Dynamics")
|
| 137 |
+
st.write(report.get('market_analysis', {}).get('dynamics', ''))
|
| 138 |
+
|
| 139 |
+
st.subheader("Competitive Landscape")
|
| 140 |
+
st.write(report.get('market_analysis', {}).get('competitive_landscape', ''))
|
| 141 |
+
|
| 142 |
+
st.subheader("Strategic Analysis")
|
| 143 |
+
st.write(report.get('market_analysis', {}).get('strategic_analysis', ''))
|
| 144 |
+
|
| 145 |
+
# Future Outlook Section
|
| 146 |
+
with st.expander("Future Outlook", expanded=False):
|
| 147 |
+
st.write(report.get('future_outlook', ''))
|
| 148 |
+
|
| 149 |
+
# Key Metrics Section
|
| 150 |
+
with st.expander("Key Metrics", expanded=False):
|
| 151 |
+
metrics = report.get('metrics', {})
|
| 152 |
+
col1, col2 = st.columns(2)
|
| 153 |
+
|
| 154 |
+
with col1:
|
| 155 |
+
st.metric("Market Size", metrics.get('market_size', 'N/A'))
|
| 156 |
+
st.metric("Growth Rate", metrics.get('growth_rate', 'N/A'))
|
| 157 |
+
|
| 158 |
+
with col2:
|
| 159 |
+
st.metric("Market Share", metrics.get('market_shares', 'N/A'))
|
| 160 |
+
st.metric("Other Metrics", metrics.get('key_metrics', 'N/A'))
|
| 161 |
+
|
| 162 |
+
# Sources Section
|
| 163 |
+
with st.expander("Sources & Appendices", expanded=False):
|
| 164 |
+
st.subheader("Sources")
|
| 165 |
+
sources = report.get('sources', [])
|
| 166 |
+
for source in sources:
|
| 167 |
+
st.markdown(f"• {source}")
|
| 168 |
+
|
| 169 |
+
st.subheader("Appendices")
|
| 170 |
+
st.write(report.get('appendices', ''))
|
| 171 |
+
|
| 172 |
+
# Download Full Report
|
| 173 |
st.download_button(
|
| 174 |
+
"Download Complete Report",
|
| 175 |
+
data=f"""
|
| 176 |
+
# Market Research Report: {topic}
|
| 177 |
+
|
| 178 |
+
## Executive Summary
|
| 179 |
+
{report.get('exec_summary', {}).get('summary', '')}
|
| 180 |
+
|
| 181 |
+
### Market Highlights
|
| 182 |
+
{report.get('exec_summary', {}).get('market_highlights', '')}
|
| 183 |
+
|
| 184 |
+
### Strategic Implications
|
| 185 |
+
{report.get('exec_summary', {}).get('strategic_implications', '')}
|
| 186 |
+
|
| 187 |
+
### Key Recommendations
|
| 188 |
+
{report.get('exec_summary', {}).get('recommendations', '')}
|
| 189 |
+
|
| 190 |
+
## Detailed Market Analysis
|
| 191 |
+
|
| 192 |
+
### Market Overview
|
| 193 |
+
{report.get('market_analysis', {}).get('overview', '')}
|
| 194 |
+
|
| 195 |
+
### Industry Dynamics
|
| 196 |
+
{report.get('market_analysis', {}).get('dynamics', '')}
|
| 197 |
+
|
| 198 |
+
### Competitive Landscape
|
| 199 |
+
{report.get('market_analysis', {}).get('competitive_landscape', '')}
|
| 200 |
+
|
| 201 |
+
### Strategic Analysis
|
| 202 |
+
{report.get('market_analysis', {}).get('strategic_analysis', '')}
|
| 203 |
+
|
| 204 |
+
## Future Outlook
|
| 205 |
+
{report.get('future_outlook', '')}
|
| 206 |
+
|
| 207 |
+
## Key Metrics
|
| 208 |
+
- Market Size: {report.get('metrics', {}).get('market_size', 'N/A')}
|
| 209 |
+
- Growth Rate: {report.get('metrics', {}).get('growth_rate', 'N/A')}
|
| 210 |
+
- Market Share: {report.get('metrics', {}).get('market_shares', 'N/A')}
|
| 211 |
+
|
| 212 |
+
## Sources
|
| 213 |
+
{chr(10).join([f"• {source}" for source in report.get('sources', [])])}
|
| 214 |
+
|
| 215 |
+
## Appendices
|
| 216 |
+
{report.get('appendices', '')}
|
| 217 |
+
""",
|
| 218 |
+
file_name=f"{topic.lower().replace(' ', '_')}_market_research.md",
|
| 219 |
+
mime="text/markdown"
|
| 220 |
)
|
| 221 |
+
|
| 222 |
except Exception as e:
|
| 223 |
st.error(f"Error displaying report: {str(e)}")
|
| 224 |
+
st.write("Raw report data:", report) # Debug information
|
| 225 |
+
|
| 226 |
if __name__ == "__main__":
|
| 227 |
main()
|