Spaces:
Runtime error
Runtime error
| #!/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 | |
| 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 | |
| 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) | |