Industry specific trend monitoring newsletter powered by perplexity & trendhunter
To upload files, please first save the app
import streamlit as st
import pandas as pd
import requests
import json
from datetime import datetime, timedelta
import time
# NOTE: Using corsproxy.io because we're in a WASM environment. If running locally,
# you can remove the corsproxy.io prefix. Some websites don't work with the proxy,
# in those cases try removing the proxy prefix.
st.set_page_config(
page_title="Industry Trend Monitor",
page_icon="📊",
layout="wide"
)
st.title("📊 Industry Trend Monitor Newsletter")
st.markdown("*Powered by Perplexity & TrendHunter insights*")
# Sidebar for configuration
with st.sidebar:
st.header("🔧 Configuration")
# Industry selection
industries = [
"Technology", "Healthcare", "Finance", "Retail", "Manufacturing",
"Energy", "Transportation", "Education", "Entertainment", "Real Estate"
]
selected_industry = st.selectbox("Select Industry", industries)
# Time range
time_ranges = ["Last 7 days", "Last 30 days", "Last 90 days"]
selected_range = st.selectbox("Time Range", time_ranges)
# Newsletter frequency
frequency = st.selectbox("Newsletter Frequency", ["Daily", "Weekly", "Monthly"])
st.divider()
# Mock API configuration
st.subheader("API Configuration")
perplexity_enabled = st.checkbox("Perplexity API", value=True)
trendhunter_enabled = st.checkbox("TrendHunter API", value=True)
# Mock data generators
def generate_perplexity_trends(industry, days=7):
"""Generate mock Perplexity trend data"""
trends = [
f"AI adoption in {industry.lower()} increases by 45%",
f"Sustainability initiatives reshape {industry.lower()} landscape",
f"Remote work technologies transform {industry.lower()} operations",
f"Data privacy regulations impact {industry.lower()} companies",
f"Digital transformation accelerates in {industry.lower()} sector"
]
data = []
for i, trend in enumerate(trends[:3]): # Limit to 3 trends
data.append({
"trend": trend,
"relevance_score": 85 - i*5,
"source": "Perplexity AI",
"date": (datetime.now() - timedelta(days=i*2)).strftime("%Y-%m-%d"),
"category": "Market Analysis"
})
return data
def generate_trendhunter_data(industry, days=7):
"""Generate mock TrendHunter data"""
innovations = [
f"Emerging {industry.lower()} startups focus on blockchain integration",
f"Consumer behavior shifts drive {industry.lower()} innovation",
f"Micro-trends in {industry.lower()} point to future opportunities",
f"Cross-industry collaborations redefine {industry.lower()} standards",
f"Gen Z preferences influence {industry.lower()} product development"
]
data = []
for i, innovation in enumerate(innovations[:3]): # Limit to 3 innovations
data.append({
"trend": innovation,
"innovation_score": 90 - i*3,
"source": "TrendHunter",
"date": (datetime.now() - timedelta(days=i*3+1)).strftime("%Y-%m-%d"),
"category": "Innovation Spotlight"
})
return data
def generate_newsletter_content(industry, perplexity_data, trendhunter_data):
"""Generate newsletter content"""
content = f"""
## 📈 {industry} Industry Trends Newsletter
*Generated on {datetime.now().strftime("%B %d, %Y")}*
### 🔍 Market Intelligence (Perplexity AI)
"""
for item in perplexity_data:
content += f"""
**{item['trend']}**
- Relevance Score: {item['relevance_score']}/100
- Date: {item['date']}
- Category: {item['category']}
---
"""
content += """
### 💡 Innovation Insights (TrendHunter)
"""
for item in trendhunter_data:
content += f"""
**{item['trend']}**
- Innovation Score: {item['innovation_score']}/100
- Date: {item['date']}
- Category: {item['category']}
---
"""
return content
# Main content area
col1, col2 = st.columns([2, 1])
with col1:
st.header(f"📊 {selected_industry} Industry Trends")
if st.button("🔄 Generate Newsletter", type="primary"):
with st.spinner("Fetching latest trends..."):
# Simulate API calls with progress
progress_bar = st.progress(0)
# Mock Perplexity data
if perplexity_enabled:
time.sleep(1)
progress_bar.progress(33)
perplexity_trends = generate_perplexity_trends(selected_industry)
else:
perplexity_trends = []
# Mock TrendHunter data
if trendhunter_enabled:
time.sleep(1)
progress_bar.progress(66)
trendhunter_trends = generate_trendhunter_data(selected_industry)
else:
trendhunter_trends = []
# Generate newsletter
time.sleep(0.5)
progress_bar.progress(100)
newsletter_content = generate_newsletter_content(
selected_industry, perplexity_trends, trendhunter_trends
)
st.success("Newsletter generated successfully!")
# Display newsletter
st.markdown(newsletter_content)
# Download button
st.download_button(
label="📥 Download Newsletter",
data=newsletter_content,
file_name=f"{selected_industry}_trends_{datetime.now().strftime('%Y%m%d')}.md",
mime="text/markdown"
)
with col2:
st.header("📋 Quick Stats")
# Mock statistics
st.metric("Active Trends", "127", "↑ 12%")
st.metric("Industry Score", "8.4/10", "↑ 0.3")
st.metric("Data Sources", "15", "↑ 2")
st.divider()
st.subheader("🎯 Trend Categories")
categories = ["Technology", "Sustainability", "Consumer Behavior", "Regulation", "Innovation"]
for cat in categories:
st.write(f"• {cat}")
st.divider()
st.subheader("⚡ Recent Updates")
st.write("• New data source integrated")
st.write("• Algorithm improved")
st.write("• Mobile app launched")
# Footer
st.divider()
col1, col2, col3 = st.columns(3)
with col1:
st.write("**Data Sources:**")
st.write("• Perplexity AI")
st.write("• TrendHunter")
with col2:
st.write("**Update Frequency:**")
st.write(f"• {frequency}")
st.write(f"• {selected_range}")
with col3:
st.write("**Export Options:**")
st.write("• Markdown")
st.write("• Email (Premium)")
# Sample data table
if st.checkbox("Show Raw Data"):
st.subheader("📊 Raw Trend Data")
# Combine data for table display
sample_data = []
for i in range(10):
sample_data.append({
"Date": (datetime.now() - timedelta(days=i)).strftime("%Y-%m-%d"),
"Industry": selected_industry,
"Trend": f"Sample trend #{i+1} for {selected_industry.lower()}",
"Source": "Perplexity" if i % 2 == 0 else "TrendHunter",
"Score": 95 - i*2,
"Category": ["Technology", "Market", "Innovation", "Consumer"][i % 4]
})
df = pd.DataFrame(sample_data)
st.table(df)
Hi! I can help you with any questions about Streamlit and Python. What would you like to know?