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|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import streamlit as st
|
| 2 |
+
import pandas as pd
|
| 3 |
+
import os
|
| 4 |
+
from phase1_agents import search_company, scrape_website, process_company_description
|
| 5 |
+
from phase2_agents import get_industry_trends
|
| 6 |
+
from phase3_agents import generate_ai_strategy, identify_revenue_opportunities, generate_report
|
| 7 |
+
from bni_agent import get_bni_benefits
|
| 8 |
+
from rag_agent import recommend_bni_connections
|
| 9 |
+
|
| 10 |
+
from datasets import load_dataset, Dataset
|
| 11 |
+
from huggingface_hub import HfApi
|
| 12 |
+
|
| 13 |
+
# Hugging Face Dataset Name
|
| 14 |
+
HF_DATASET_NAME = "GiantAnalytics/visionary-ai-user-data"
|
| 15 |
+
|
| 16 |
+
# Function to Save Data to Hugging Face Dataset
|
| 17 |
+
def save_data_hf(data):
|
| 18 |
+
try:
|
| 19 |
+
dataset = load_dataset(HF_DATASET_NAME)
|
| 20 |
+
df = pd.DataFrame(dataset["train"])
|
| 21 |
+
new_df = pd.DataFrame([data])
|
| 22 |
+
df = pd.concat([df, new_df], ignore_index=True)
|
| 23 |
+
new_dataset = Dataset.from_pandas(df)
|
| 24 |
+
new_dataset.push_to_hub(HF_DATASET_NAME, split="train")
|
| 25 |
+
print("β
Data saved successfully to Hugging Face Dataset")
|
| 26 |
+
except Exception as e:
|
| 27 |
+
print(f"β Failed to save data: {e}")
|
| 28 |
+
|
| 29 |
+
# Streamlit UI
|
| 30 |
+
def main():
|
| 31 |
+
st.title("π Visionary AI - AI Strategy Generator")
|
| 32 |
+
st.write("π This tool provides an AI-driven business strategy report tailored for your company.")
|
| 33 |
+
st.write("π Powered by **State-of-the-Art Reasoning Models** for AI integration insights.")
|
| 34 |
+
|
| 35 |
+
# Initialize Session State Variables
|
| 36 |
+
session_keys = [
|
| 37 |
+
"company_data", "industry_trends", "ai_strategy",
|
| 38 |
+
"revenue_opportunities", "bni_benefits", "bni_connections"
|
| 39 |
+
]
|
| 40 |
+
|
| 41 |
+
for key in session_keys:
|
| 42 |
+
if key not in st.session_state:
|
| 43 |
+
st.session_state[key] = None
|
| 44 |
+
|
| 45 |
+
# Collect User Information
|
| 46 |
+
name = st.text_input("π€ Your Name")
|
| 47 |
+
email = st.text_input("π§ Email")
|
| 48 |
+
mobile = st.text_input("π± Mobile Number")
|
| 49 |
+
company_name = st.text_input("π’ Company Name")
|
| 50 |
+
company_industry = st.text_input("πΌ Industry (e.g., Healthcare, Finance, IT)")
|
| 51 |
+
|
| 52 |
+
# Select Company Data Input Method
|
| 53 |
+
st.subheader("π Provide Company Information")
|
| 54 |
+
input_method = st.radio("Choose a method to provide company details:",
|
| 55 |
+
["Company Website", "Web Search", "Manual Description"])
|
| 56 |
+
|
| 57 |
+
progress_bar = st.progress(0)
|
| 58 |
+
|
| 59 |
+
# Handle Company Data Input
|
| 60 |
+
if input_method == "Company Website":
|
| 61 |
+
website_url = st.text_input("π Enter Company Website URL")
|
| 62 |
+
if st.button("π Scrape Website"):
|
| 63 |
+
st.session_state.company_data = scrape_website(website_url)
|
| 64 |
+
progress_bar.progress(20)
|
| 65 |
+
|
| 66 |
+
elif input_method == "Web Search":
|
| 67 |
+
if st.button("π Search Company Online"):
|
| 68 |
+
st.session_state.company_data = search_company(company_name)
|
| 69 |
+
progress_bar.progress(20)
|
| 70 |
+
|
| 71 |
+
elif input_method == "Manual Description":
|
| 72 |
+
company_description = st.text_area("π Enter Company Description")
|
| 73 |
+
if st.button("β Process Description"):
|
| 74 |
+
st.session_state.company_data = process_company_description(company_description)
|
| 75 |
+
progress_bar.progress(20)
|
| 76 |
+
|
| 77 |
+
# **Execute All Phases Automatically After Company Data is Available**
|
| 78 |
+
if st.session_state.company_data:
|
| 79 |
+
st.subheader("β
Company Information Extracted")
|
| 80 |
+
st.write(st.session_state.company_data)
|
| 81 |
+
progress_bar.progress(40)
|
| 82 |
+
|
| 83 |
+
# **BNI Benefits & Recommendations** (Moved before AI)
|
| 84 |
+
try:
|
| 85 |
+
st.session_state.bni_benefits = get_bni_benefits(st.session_state.company_data)
|
| 86 |
+
|
| 87 |
+
# Call the RAG agent here:
|
| 88 |
+
st.session_state.bni_connections = recommend_bni_connections(st.session_state.company_data)
|
| 89 |
+
progress_bar.progress(60) # Updated progress position
|
| 90 |
+
except Exception as e:
|
| 91 |
+
print(f"β Error fetching BNI data: {e}")
|
| 92 |
+
st.session_state.bni_benefits = "No BNI data available."
|
| 93 |
+
st.session_state.bni_connections = "No relevant BNI connections found."
|
| 94 |
+
|
| 95 |
+
if st.session_state.bni_benefits:
|
| 96 |
+
st.subheader("π BNI Membership Benefits for Your Business")
|
| 97 |
+
st.write(st.session_state.bni_benefits)
|
| 98 |
+
|
| 99 |
+
if st.session_state.bni_connections:
|
| 100 |
+
st.subheader("π€ Recommended BNI Pearl Chapter Connections")
|
| 101 |
+
st.write(st.session_state.bni_connections)
|
| 102 |
+
progress_bar.progress(75) # Updated progress position
|
| 103 |
+
|
| 104 |
+
# Industry Analysis (Hidden from Frontend, but required for AI Strategy)
|
| 105 |
+
st.session_state.industry_trends = get_industry_trends(company_industry)
|
| 106 |
+
|
| 107 |
+
# AI Strategy & Implementation (Comes after BNI)
|
| 108 |
+
st.session_state.ai_strategy = generate_ai_strategy(
|
| 109 |
+
st.session_state.company_data, st.session_state.industry_trends)
|
| 110 |
+
|
| 111 |
+
# Revenue Opportunities
|
| 112 |
+
st.session_state.revenue_opportunities = identify_revenue_opportunities(
|
| 113 |
+
st.session_state.company_data, st.session_state.ai_strategy)
|
| 114 |
+
progress_bar.progress(90)
|
| 115 |
+
|
| 116 |
+
if st.session_state.ai_strategy:
|
| 117 |
+
st.subheader("π AI Strategy & Revenue Opportunities")
|
| 118 |
+
st.write(st.session_state.ai_strategy)
|
| 119 |
+
st.write(st.session_state.revenue_opportunities)
|
| 120 |
+
progress_bar.progress(95)
|
| 121 |
+
|
| 122 |
+
# Generate Final Report (Including BNI Data)
|
| 123 |
+
progress_bar.progress(99)
|
| 124 |
+
report_filename = generate_report(
|
| 125 |
+
company_name,
|
| 126 |
+
st.session_state.company_data,
|
| 127 |
+
st.session_state.ai_strategy,
|
| 128 |
+
st.session_state.revenue_opportunities,
|
| 129 |
+
st.session_state.bni_benefits,
|
| 130 |
+
st.session_state.bni_connections
|
| 131 |
+
)
|
| 132 |
+
st.success(f"π Report Generated: **{report_filename}**")
|
| 133 |
+
|
| 134 |
+
# Provide download button for the generated PDF
|
| 135 |
+
with open(report_filename, "rb") as pdf_file:
|
| 136 |
+
PDFbyte = pdf_file.read()
|
| 137 |
+
|
| 138 |
+
st.download_button(
|
| 139 |
+
label="π₯ Download AI Strategy Report (PDF)",
|
| 140 |
+
data=PDFbyte,
|
| 141 |
+
file_name=report_filename,
|
| 142 |
+
mime='application/octet-stream'
|
| 143 |
+
)
|
| 144 |
+
|
| 145 |
+
progress_bar.progress(100)
|
| 146 |
+
|
| 147 |
+
# Save Data to Hugging Face
|
| 148 |
+
if st.session_state.company_data and st.session_state.ai_strategy:
|
| 149 |
+
user_data = {
|
| 150 |
+
"name": name, "email": email, "mobile": mobile, "company_name": company_name,
|
| 151 |
+
"industry": company_industry, "input_method": input_method, "company_data": st.session_state.company_data,
|
| 152 |
+
"ai_strategy": st.session_state.ai_strategy,
|
| 153 |
+
"revenue_opportunities": st.session_state.revenue_opportunities,
|
| 154 |
+
"bni_benefits": st.session_state.bni_benefits,
|
| 155 |
+
"bni_connections": st.session_state.bni_connections # β add this
|
| 156 |
+
}
|
| 157 |
+
save_data_hf(user_data)
|
| 158 |
+
|
| 159 |
+
# Footer
|
| 160 |
+
st.markdown("---")
|
| 161 |
+
st.markdown("π **Powered by Giant Analytics | Contact Us: (+91) 96533 20500**")
|
| 162 |
+
|
| 163 |
+
if __name__ == "__main__":
|
| 164 |
+
main()
|