""" Main Gradio application for EDA-Generator HuggingFace Space. Features a chatbot interface and dataset EDA visualizations. """ import gradio as gr from chatbot import chat_stream_fn from eda import ( create_prompt_length_histogram, create_word_count_boxplot, create_top_words_chart, create_length_vs_words_scatter, create_category_distribution, create_summary_stats, load_prompts_dataset ) # Custom CSS for premium aesthetics CUSTOM_CSS = """ /* Dark theme with gradient accents */ .gradio-container { background: linear-gradient(135deg, #1a1a2e 0%, #16213e 50%, #0f3460 100%) !important; } /* Header styling */ .header-title { text-align: center; background: linear-gradient(90deg, #667eea, #764ba2, #f093fb); -webkit-background-clip: text; -webkit-text-fill-color: transparent; font-size: 2.5rem; font-weight: 800; margin-bottom: 0.5rem; } .header-subtitle { text-align: center; color: #a0aec0; font-size: 1.1rem; margin-bottom: 2rem; } /* Tab styling */ .tabs { border-radius: 12px !important; overflow: hidden; } /* Chat container */ .chatbot { border-radius: 16px !important; border: 1px solid rgba(102, 126, 234, 0.3) !important; background: rgba(26, 26, 46, 0.8) !important; } /* Plot containers */ .plot-container { border-radius: 12px; padding: 1rem; background: rgba(255, 255, 255, 0.03); border: 1px solid rgba(102, 126, 234, 0.2); margin: 0.5rem 0; } /* Stats table */ .dataframe { border-radius: 8px !important; overflow: hidden; } /* Buttons */ .primary-btn { background: linear-gradient(90deg, #667eea, #764ba2) !important; border: none !important; border-radius: 8px !important; } /* Micro-animations */ .tab-nav button { transition: all 0.3s ease !important; } .tab-nav button:hover { transform: translateY(-2px); box-shadow: 0 4px 12px rgba(102, 126, 234, 0.4); } """ def create_app() -> gr.Blocks: """ Create the main Gradio application with tabs for chatbot and EDA. Returns: Gradio Blocks application """ with gr.Blocks( css=CUSTOM_CSS, theme=gr.themes.Soft( primary_hue="purple", secondary_hue="indigo", neutral_hue="slate", ).set( body_background_fill="*neutral_950", block_background_fill="*neutral_900", block_border_width="1px", block_border_color="*primary_700", input_background_fill="*neutral_800", button_primary_background_fill="*primary_600", ), title="EDA-Generator | AI Chatbot & Dataset Analysis" ) as demo: # Header gr.HTML("""

🚀 EDA-Generator

AI-Powered Chatbot & Dataset Exploratory Analysis

""") with gr.Tabs() as tabs: # ===== CHATBOT TAB ===== with gr.TabItem("đŸ’Ŧ AI Chatbot", id="chatbot"): gr.Markdown(""" ### Chat with GPT-OSS-20B A powerful open-source language model for conversation, coding help, and more. """) chatbot_interface = gr.ChatInterface( fn=chat_stream_fn, chatbot=gr.Chatbot( height=500, placeholder="Ask me anything!
I can help with coding, analysis, creative writing, and more.", show_copy_button=True, ), textbox=gr.Textbox( placeholder="Type your message here...", container=False, scale=7 ), retry_btn="🔄 Retry", undo_btn="â†Šī¸ Undo", clear_btn="đŸ—‘ī¸ Clear", examples=[ "Explain machine learning in simple terms", "Write a Python function to reverse a string", "What are the best practices for data visualization?", "Help me write a creative story opening" ], ) # ===== EDA TAB ===== with gr.TabItem("📊 Dataset EDA", id="eda"): gr.Markdown(""" ### Exploring `fka/awesome-chatgpt-prompts` Interactive visualizations of the popular ChatGPT prompts dataset. """) # Summary Statistics with gr.Row(): with gr.Column(scale=1): gr.Markdown("#### 📋 Summary Statistics") stats_df = create_summary_stats() gr.Dataframe( value=stats_df, headers=["Metric", "Value"], interactive=False, wrap=True ) # Row 1: Distribution plots with gr.Row(): with gr.Column(): gr.Markdown("#### Distribution of Prompt Lengths") length_plot = gr.Plot(value=create_prompt_length_histogram()) with gr.Column(): gr.Markdown("#### Word Count Distribution") word_plot = gr.Plot(value=create_word_count_boxplot()) # Row 2: Analysis plots with gr.Row(): with gr.Column(): gr.Markdown("#### Top Words Analysis") words_plot = gr.Plot(value=create_top_words_chart()) with gr.Column(): gr.Markdown("#### Length vs Words Correlation") scatter_plot = gr.Plot(value=create_length_vs_words_scatter()) # Row 3: Category distribution with gr.Row(): with gr.Column(): gr.Markdown("#### Category Distribution") category_plot = gr.Plot(value=create_category_distribution()) # Sample Data Preview with gr.Accordion("📄 Sample Data Preview", open=False): df = load_prompts_dataset() gr.Dataframe( value=df[['act', 'prompt']].head(10), headers=["Category (Act)", "Prompt"], wrap=True, max_height=300 ) # ===== ABOUT TAB ===== with gr.TabItem("â„šī¸ About", id="about"): gr.Markdown(""" ## About EDA-Generator This HuggingFace Space demonstrates: ### 🤖 AI Chatbot - Powered by **OpenAI's GPT-OSS-20B** model - 21 billion parameters with MoE architecture - Streaming responses for better UX - Built with HuggingFace Transformers ### 📊 Dataset Analysis - Analyzes the **fka/awesome-chatgpt-prompts** dataset - 1,040 curated prompts for various AI personas - Interactive Plotly visualizations ### đŸ› ī¸ Tech Stack - **Frontend**: Gradio - **ML**: HuggingFace Transformers - **Visualization**: Plotly, Matplotlib, Seaborn - **Data**: HuggingFace Datasets --- **Created with â¤ī¸ using HuggingFace** """) # Footer gr.HTML("""

🌟 Star this Space if you find it useful!

""") return demo # Create and launch the app demo = create_app() if __name__ == "__main__": demo.launch()