File size: 8,601 Bytes
6822668
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
# app_gradio_enhanced.py
import gradio as gr
from client_agent import answer_sync


def chat_fn(message: str, history: list[dict]):
    """Enhanced chat function with better error handling"""
    try:
        reply = answer_sync(message)
        return reply
    except Exception as e:
        return f"⚠️ Error: {str(e)}"


# Custom CSS for professional styling
custom_css = """
/* Main container styling */
.gradio-container {
    max-width: 1200px !important;
    margin: 0 auto !important;
}

/* Header styling */
.header-text {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    text-align: center;
    font-weight: bold;
    margin-bottom: 1rem;
}

/* Chat message styling */
.message-wrap {
    border-radius: 12px !important;
    margin: 8px 0 !important;
    padding: 12px 16px !important;
}

.user-message {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%) !important;
    color: white !important;
}

.bot-message {
    background: #f8f9fa !important;
    border-left: 4px solid #667eea !important;
}

/* Input styling */
.input-container {
    border-radius: 25px !important;
    border: 2px solid #e9ecef !important;
    transition: all 0.3s ease !important;
}

.input-container:focus-within {
    border-color: #667eea !important;
    box-shadow: 0 0 0 3px rgba(102, 126, 234, 0.1) !important;
}

/* Button styling */
.submit-btn {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%) !important;
    border: none !important;
    border-radius: 20px !important;
    padding: 10px 20px !important;
    font-weight: 600 !important;
    transition: all 0.3s ease !important;
}

.submit-btn:hover {
    transform: translateY(-2px) !important;
    box-shadow: 0 4px 12px rgba(102, 126, 234, 0.3) !important;
}

/* Status indicators */
.status-indicator {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 6px 12px;
    border-radius: 20px;
    font-size: 14px;
    font-weight: 500;
}

.status-online {
    background: #d4edda;
    color: #155724;
    border: 1px solid #c3e6cb;
}

/* Loading animation */
@keyframes pulse {
    0% { opacity: 1; }
    50% { opacity: 0.5; }
    100% { opacity: 1; }
}

.loading {
    animation: pulse 1.5s infinite;
}

/* Responsive design */
@media (max-width: 768px) {
    .gradio-container {
        padding: 10px !important;
    }
    
    .message-wrap {
        margin: 4px 0 !important;
        padding: 8px 12px !important;
    }
}

/* Dark mode support */
.dark .bot-message {
    background: #2d3748 !important;
    color: #e2e8f0 !important;
    border-left-color: #667eea !important;
}

.dark .input-container {
    background: #2d3748 !important;
    border-color: #4a5568 !important;
    color: #e2e8f0 !important;
}
"""


def create_enhanced_interface():
    """Create an enhanced Gradio interface with professional styling"""
    
    with gr.Blocks(
        css=custom_css,
        theme=gr.themes.Soft(
            primary_hue="blue",
            secondary_hue="purple",
            neutral_hue="slate",
            font=[
                gr.themes.GoogleFont("Inter"),
                "ui-sans-serif", 
                "system-ui", 
                "sans-serif"
            ]
        ),
        title="πŸ“š Docs Navigator - AI-Powered Documentation Assistant",
        analytics_enabled=False
    ) as interface:
        
        # Header section
        with gr.Row():
            gr.Markdown(
                """
                # πŸ“š Docs Navigator MCP
                ### AI-Powered Documentation Assistant
                
                Ask questions about your documentation and get intelligent, contextual answers powered by Claude and MCP.
                """,
                elem_classes=["header-text"]
            )
        
        # Status indicator
        with gr.Row():
            gr.HTML(
                """
                <div class="status-indicator status-online">
                    <span>🟒</span>
                    <span>MCP Server Connected</span>
                </div>
                """,
                visible=True
            )
        
        # Main chat interface
        chat = gr.ChatInterface(
            fn=chat_fn,
            type="messages",
            chatbot=gr.Chatbot(
                height=500,
                show_label=False,
                container=True,
                bubble_full_width=False,
                avatar_images=(
                    "https://api.dicebear.com/7.x/thumbs/svg?seed=user&backgroundColor=667eea",
                    "https://api.dicebear.com/7.x/bottts/svg?seed=bot&backgroundColor=764ba2"
                )
            ),
            textbox=gr.Textbox(
                placeholder="Ask me anything about your documentation... πŸ’­",
                container=False,
                scale=7,
                elem_classes=["input-container"]
            ),
            submit_btn=gr.Button(
                "Send πŸš€", 
                variant="primary",
                elem_classes=["submit-btn"]
            ),
            retry_btn=gr.Button("πŸ”„ Retry", variant="secondary"),
            undo_btn=gr.Button("↩️ Undo", variant="secondary"),
            clear_btn=gr.Button("πŸ—‘οΈ Clear", variant="secondary"),
            examples=[
                "How do I set up AuroraAI?",
                "What are the troubleshooting steps for connection issues?",
                "Tell me about the configuration options",
                "What does the overview documentation say?",
                "How do I get started with this project?"
            ]
        )
        
        # Footer section
        with gr.Row():
            gr.Markdown(
                """
                ---
                <div style="text-align: center; color: #6c757d; font-size: 14px; margin-top: 20px;">
                    <p>
                        πŸ”§ Powered by <strong>Model Context Protocol (MCP)</strong> | 
                        πŸ€– <strong>Claude AI</strong> | 
                        🎨 <strong>Gradio</strong>
                    </p>
                    <p style="font-size: 12px; margin-top: 10px;">
                        πŸ’‘ Tip: Ask specific questions about your documentation for the best results!
                    </p>
                </div>
                """,
                elem_classes=["footer"]
            )
    
    return interface


# Create the demo with different styling options
def create_minimal_interface():
    """Create a minimal, clean interface"""
    return gr.ChatInterface(
        fn=chat_fn,
        type="messages",
        title="πŸ“š Docs Navigator",
        description="Clean, minimal documentation assistant",
        theme=gr.themes.Monochrome(),
        chatbot=gr.Chatbot(height=400, show_label=False),
        textbox=gr.Textbox(placeholder="Ask about your docs...", container=False),
        examples=["Setup guide", "Troubleshooting", "Configuration"]
    )


def create_corporate_interface():
    """Create a corporate/professional interface"""
    corporate_theme = gr.themes.Default(
        primary_hue="slate",
        secondary_hue="blue",
        neutral_hue="gray"
    ).set(
        body_background_fill="white",
        panel_background_fill="*neutral_50",
        button_primary_background_fill="*primary_600"
    )
    
    return gr.ChatInterface(
        fn=chat_fn,
        type="messages",
        title="Documentation Assistant",
        description="Enterprise AI Documentation System",
        theme=corporate_theme,
        chatbot=gr.Chatbot(
            height=450, 
            show_label=False,
            bubble_full_width=False
        ),
        textbox=gr.Textbox(
            placeholder="Enter your documentation question...",
            container=False
        )
    )


if __name__ == "__main__":
    import sys
    
    # Choose interface style based on command line argument
    style = sys.argv[1] if len(sys.argv) > 1 else "enhanced"
    
    if style == "minimal":
        demo = create_minimal_interface()
    elif style == "corporate":
        demo = create_corporate_interface()
    else:  # enhanced (default)
        demo = create_enhanced_interface()
    
    # Launch with professional settings
    demo.launch(
        server_name="127.0.0.1",
        server_port=7860,
        share=False,
        show_error=True,
        quiet=False,
        favicon_path=None,  # You can add a custom favicon here
        ssl_verify=False,
        show_tips=True
    )