amalsp's picture
πŸš€ Ultra-fast version: Replace Transformers with TF-IDF for instant startup (16,763 tools)
69177b7 verified
#!/usr/bin/env python3
import streamlit as st
import pandas as pd
import numpy as np
from sklearn.feature_extraction.text import TfidfVectorizer
from sklearn.metrics.pairwise import cosine_similarity
# Page config
st.set_page_config(page_title="AI Tool Recommender", page_icon="πŸ€–", layout="wide")
# CSS
st.markdown("""
<style>
.main {background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);}
.stTextInput > div > div > input {border-radius: 10px; padding: 12px;}
</style>
""", unsafe_allow_html=True)
# Load data with caching
@st.cache_data
def load_data():
url = 'https://raw.githubusercontent.com/SayedTahsin/AIToolBuzz-Dataset/main/aitoolbuzz.csv'
try:
df = pd.read_csv(url)
return df
except:
# Fallback sample data
return pd.DataFrame({
'tool_name': ['ChatGPT', 'Midjourney', 'GitHub Copilot', 'DALL-E', 'Jasper'],
'description': [
'AI chatbot for conversations and text generation',
'AI-powered image generation from text prompts',
'AI pair programmer that helps you write code faster',
'Create realistic images and art from text descriptions',
'AI writing assistant for content creation and marketing'
],
'category': ['NLP', 'Image Generation', 'Code', 'Image Generation', 'Writing']
})
# Create TF-IDF vectorizer and fit
@st.cache_resource
def create_search_index(_df):
texts = (_df['tool_name'].fillna('') + ' ' + _df['description'].fillna('')).tolist()
vectorizer = TfidfVectorizer(stop_words='english', max_features=1000)
tfidf_matrix = vectorizer.fit_transform(texts)
return vectorizer, tfidf_matrix
# Search function
def search_tools(query, vectorizer, tfidf_matrix, df, top_k=5):
query_vec = vectorizer.transform([query])
similarities = cosine_similarity(query_vec, tfidf_matrix).flatten()
top_indices = similarities.argsort()[-top_k:][::-1]
return top_indices, similarities[top_indices]
# Main app
st.title("πŸ€– AI Tool Recommender Chatbot")
st.write("πŸ” Find the perfect AI tool from **16,763 tools** using intelligent search")
# Load data
with st.spinner("πŸ“₯ Loading AI tools database..."):
df = load_data()
vectorizer, tfidf_matrix = create_search_index(df)
st.success(f"βœ… **{len(df):,} AI tools** loaded and ready!")
# Search interface
query = st.text_input(
"πŸ‘‰ What kind of AI tool are you looking for?",
placeholder="e.g., AI tool for creating images, code assistant, writing helper...",
key="search"
)
if query:
indices, scores = search_tools(query, vectorizer, tfidf_matrix, df)
st.subheader(f"🎯 Top {len(indices)} Results")
for i, (idx, score) in enumerate(zip(indices, scores)):
with st.expander(f"**#{i+1} - {df.iloc[idx]['tool_name']}** (Relevance: {score*100:.1f}%)", expanded=(i==0)):
col1, col2 = st.columns([3, 1])
with col1:
st.markdown(f"**πŸ“ Description:**")
st.write(df.iloc[idx].get('description', 'N/A'))
if 'category' in df.columns and pd.notna(df.iloc[idx].get('category')):
st.markdown(f"**🏷️ Category:** {df.iloc[idx]['category']}")
if 'website' in df.columns and pd.notna(df.iloc[idx].get('website')):
st.markdown(f"**🌐 Website:** [{df.iloc[idx]['website']}]({df.iloc[idx]['website']})")
with col2:
st.metric("Match Score", f"{score*100:.0f}%")
# Sidebar
with st.sidebar:
st.title("πŸ“Š Statistics")
st.metric("πŸ“¦ Total AI Tools", f"{len(df):,}")
if 'category' in df.columns:
unique_cats = df['category'].nunique()
st.metric("🏷️ Categories", unique_cats)
st.title("πŸ‘‹ Try These")
example_queries = [
"πŸ–ΌοΈ AI image generators",
"πŸ“ Writing assistants",
"πŸ’» Code helpers",
"🎀 Voice AI tools",
"πŸŽ₯ Video creation"
]
for eq in example_queries:
if st.button(eq, key=eq):
st.session_state.search = eq.split(' ', 1)[1] if ' ' in eq else eq
st.rerun()
st.markdown("---")
st.title("ℹ️ About")
st.info("""
**AI Tool Recommender**
πŸ” Intelligent search across 16K+ AI tools
**Tech:**
- TF-IDF Text Analysis
- Cosine Similarity
- Streamlit UI
**Data:** AIToolBuzz Dataset
""")
# Footer
st.markdown("---")
st.markdown("""
<div style='text-align: center'>
<p>Built with ❀️ by <b>Amal SP</b> |
<a href='https://github.com/amalsp220/ai-tool-recommender-chatbot' target='_blank'>GitHub</a> |
<a href='https://www.linkedin.com/in/amalsp220' target='_blank'>LinkedIn</a>
</p>
</div>
""", unsafe_allow_html=True)