File size: 8,474 Bytes
043c791
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
"""
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("""
            <div style="padding: 2rem 0;">
                <h1 class="header-title">πŸš€ EDA-Generator</h1>
                <p class="header-subtitle">
                    AI-Powered Chatbot & Dataset Exploratory Analysis
                </p>
            </div>
        """)
        
        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="<strong>Ask me anything!</strong><br>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("""
            <div style="text-align: center; padding: 2rem 0; color: #667eea; font-size: 0.9rem;">
                <p>🌟 Star this Space if you find it useful!</p>
            </div>
        """)
    
    return demo


# Create and launch the app
demo = create_app()

if __name__ == "__main__":
    demo.launch()