Spaces:
Sleeping
Sleeping
File size: 3,551 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 |
# app_gradio.py
import gradio as gr
import sys
import os
sys.path.append(os.path.join(os.path.dirname(__file__), '..', '..'))
from src.agent.client import answer_sync
def chat_fn(message: str, history: list[dict]):
"""Enhanced chat function with better error handling and user feedback"""
try:
if not message.strip():
return "Please enter a question about the documentation."
reply = answer_sync(message)
return reply
except Exception as e:
return f"β οΈ I encountered an error while processing your question: {str(e)}\n\nPlease try again or rephrase your question."
def main():
"""Main entry point for the application when run via uv."""
print("π Starting Docs Navigator MCP...")
print("π AI-Powered Documentation Assistant")
print("π The app will be available at: http://127.0.0.1:7862")
print("π‘ Ask questions about your documentation!")
print("-" * 50)
demo.launch(
server_name="127.0.0.1",
server_port=7862,
show_error=True,
share=False
)
# Professional theme configuration
professional_theme = gr.themes.Soft(
primary_hue="blue",
secondary_hue="slate",
neutral_hue="gray",
font=[
gr.themes.GoogleFont("Inter"),
"ui-sans-serif",
"system-ui",
"sans-serif"
]
).set(
body_background_fill="*neutral_50",
panel_background_fill="white",
button_primary_background_fill="*primary_600",
button_primary_background_fill_hover="*primary_700",
input_background_fill="white"
)
# Custom CSS for enhanced styling
custom_css = """
.gradio-container {
max-width: 1000px !important;
margin: 0 auto !important;
}
.chat-interface {
border-radius: 12px !important;
box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1) !important;
}
.message {
border-radius: 8px !important;
margin: 6px 0 !important;
}
/* Enhanced input styling */
.input-container textarea {
border-radius: 8px !important;
border: 2px solid #e5e7eb !important;
transition: all 0.2s ease !important;
}
.input-container textarea:focus {
border-color: #3b82f6 !important;
box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.1) !important;
}
"""
demo = gr.ChatInterface(
fn=chat_fn,
type="messages",
title="π Docs Navigator MCP",
description="π€ **AI-Powered Documentation Assistant**\n\nAsk questions about your documentation and get intelligent, contextual answers. Powered by Claude AI and Model Context Protocol.",
theme=professional_theme,
css=custom_css,
chatbot=gr.Chatbot(
height=500,
show_label=False,
type="messages",
avatar_images=(
"https://api.dicebear.com/7.x/thumbs/svg?seed=user&backgroundColor=3b82f6",
"https://api.dicebear.com/7.x/bottts/svg?seed=docs&backgroundColor=1e40af"
)
),
textbox=gr.Textbox(
placeholder="π Ask me anything about your documentation...",
container=False,
scale=7
),
examples=[
"π How do I get started with this project?",
"βοΈ What configuration options are available?",
"π§ How do I troubleshoot connection issues?",
"π Tell me about the setup process",
"π‘ What does the overview documentation explain?",
"π What information is in the PDF documents?"
]
)
if __name__ == "__main__":
demo.launch(
server_name="127.0.0.1",
server_port=7860,
show_error=True
)
|