Spaces:
Runtime error
Runtime error
| import streamlit as st | |
| import plotly.express as px | |
| import plotly.graph_objects as go | |
| import pandas as pd | |
| import numpy as np | |
| from datetime import datetime | |
| from transformers import AutoModelForCausalLM, AutoTokenizer | |
| import torch | |
| # --- App Configuration --- | |
| st.set_page_config( | |
| page_title="Prospira | Data-Driven Business Insights", | |
| page_icon="📈", | |
| layout="wide" | |
| ) | |
| # --- Sidebar Navigation --- | |
| st.sidebar.image("https://via.placeholder.com/150", use_column_width=True) # Placeholder for Prospira logo | |
| st.sidebar.title("Prospira Navigation") | |
| page = st.sidebar.radio("Go to", ["🏠 Home", "📊 Business Dashboard", "🔍 Data Analytics", "💡 Brainstorm Hub", "🤖 AI Assistant"]) | |
| # --- Homepage --- | |
| if page == "🏠 Home": | |
| st.title("🚀 Welcome to Prospira") | |
| st.subheader("📊 Data-Driven Solutions for Businesses and Creators") | |
| st.markdown(""" | |
| **Prospira** empowers businesses and creators to enhance their content, products, and marketing strategies using AI-driven insights. | |
| ### **✨ Key Features** | |
| - **📈 Performance Analytics:** Real-time insights into business metrics. | |
| - **🔎 Competitive Analysis:** Benchmark your business against competitors. | |
| - **💡 Smart Product Ideas:** AI-generated recommendations for future products and content. | |
| - **🧠 AI Business Mentor:** Personalized AI guidance for strategy and growth. | |
| Explore how **Prospira** can help optimize your decision-making and drive success! 💡🚀 | |
| """) | |
| st.image("https://via.placeholder.com/800x400", use_column_width=True) # Placeholder for banner image | |
| # --- Business Dashboard --- | |
| elif page == "📊 Business Dashboard": | |
| st.title("📊 Prospira Business Dashboard") | |
| st.subheader("Real-time Performance Insights") | |
| # Generate Sample Business Data | |
| dates = pd.date_range(start='2024-01-01', end='2024-01-31') | |
| data = pd.DataFrame({ | |
| 'Date': dates, | |
| 'Revenue': np.random.randint(800, 5000, len(dates)), | |
| 'Users': np.random.randint(100, 500, len(dates)), | |
| 'Engagement': np.random.uniform(0.3, 0.9, len(dates)), | |
| 'Profit': np.random.uniform(200, 1500, len(dates)), | |
| 'Category': np.random.choice(['Social Media', 'E-commerce', 'SaaS', 'Services'], len(dates)) | |
| }) | |
| # Top-Level KPIs | |
| col1, col2, col3, col4 = st.columns(4) | |
| col1.metric("Total Revenue", f"${data['Revenue'].sum():,.0f}") | |
| col2.metric("Total Users", f"{data['Users'].sum():,}") | |
| col3.metric("Avg Engagement", f"{data['Engagement'].mean():.2%}") | |
| col4.metric("Profit", f"${data['Profit'].sum():,.0f}") | |
| # Revenue & Profit Trends | |
| st.subheader("📈 Revenue & Profit Trends") | |
| fig = go.Figure() | |
| fig.add_trace(go.Scatter(x=data['Date'], y=data['Revenue'], mode='lines', name='Revenue', line=dict(color='blue'))) | |
| fig.add_trace(go.Scatter(x=data['Date'], y=data['Profit'], mode='lines', name='Profit', line=dict(color='green'))) | |
| st.plotly_chart(fig, use_container_width=True) | |
| # Category Performance Breakdown | |
| st.subheader("📊 Category Performance") | |
| category_summary = data.groupby('Category')[['Revenue', 'Users', 'Engagement']].mean().reset_index() | |
| fig_bar = px.bar(category_summary, x='Category', y='Revenue', color='Engagement', title="Revenue by Category") | |
| st.plotly_chart(fig_bar, use_container_width=True) | |
| # --- Data Analytics Page --- | |
| elif page == "🔍 Data Analytics": | |
| st.title("🔍 Upload and Analyze Your Data") | |
| uploaded_file = st.file_uploader("Upload your CSV file", type=['csv']) | |
| if uploaded_file: | |
| df = pd.read_csv(uploaded_file) | |
| st.write("### Preview of Your Data:") | |
| st.dataframe(df.head()) | |
| st.write("### 📊 Basic Statistics") | |
| st.write(df.describe()) | |
| st.write("### 📈 Data Visualization") | |
| col1, col2 = st.columns(2) | |
| x_col = col1.selectbox("X-Axis", df.columns) | |
| y_col = col2.selectbox("Y-Axis", df.columns) | |
| fig = px.scatter(df, x=x_col, y=y_col, title=f"Scatter Plot of {x_col} vs {y_col}") | |
| st.plotly_chart(fig, use_container_width=True) | |
| # --- Brainstorming Hub --- | |
| elif page == "💡 Brainstorm Hub": | |
| st.title("💡 AI-Powered Product Brainstorming") | |
| product_name = st.text_input("Product Name") | |
| category = st.selectbox("Category", ["Digital", "Physical", "Service"]) | |
| audience = st.multiselect("Target Audience", ["Students", "Professionals", "Businesses"]) | |
| description = st.text_area("Product Description") | |
| price_range = st.slider("Price Range ($)", 0, 1000, (50, 200)) | |
| if st.button("Generate Insights"): | |
| st.success("AI-generated insights will appear here.") | |
| st.write(f"💡 **Suggested Price**: ${np.mean(price_range):.2f}") | |
| st.write(f"🚀 **Market Opportunity**: High") | |
| # --- AI Assistant Page --- | |
| elif page == "🤖 AI Assistant": | |
| st.title("🤖 Prospira AI Business Mentor") | |
| class LLaMAAssistant: | |
| def __init__(self, model_name="meta-llama/Llama-2-7b-chat-hf"): | |
| try: | |
| self.tokenizer = AutoTokenizer.from_pretrained(model_name) | |
| self.model = AutoModelForCausalLM.from_pretrained( | |
| model_name, torch_dtype=torch.float16, device_map="auto" | |
| ) | |
| except Exception as e: | |
| st.error(f"Model loading error: {e}") | |
| self.model = None | |
| self.tokenizer = None | |
| def generate_response(self, prompt: str) -> str: | |
| if not self.model or not self.tokenizer: | |
| return "LLM not initialized." | |
| input_ids = self.tokenizer(prompt, return_tensors="pt").input_ids.to(self.model.device) | |
| output = self.model.generate(input_ids, max_length=300) | |
| return self.tokenizer.decode(output[0], skip_special_tokens=True) | |
| assistant = LLaMAAssistant() | |
| user_input = st.text_area("Ask Prospira AI for Business Advice:") | |
| if st.button("Get AI Insights"): | |
| response = assistant.generate_response(user_input) | |
| st.write("**🧠 AI Response:**") | |
| st.info(response) | |