mrunalkakirwar's picture
minor changes (#3)
6eadf91 verified
import gradio as gr
import os
# Import the enhanced crew classes
from crew import EnhancedTicketSupportCrew
# Set your OpenAI API key
os.environ[
"OPENAI_API_KEY"] = "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"
# Path to the tickets.json file
project_root = os.path.dirname(os.path.abspath(__file__))
json_file_path = os.path.join(project_root, "tickets.json")
# Function to provide the file for download
def download_json():
return json_file_path
def process_query(user_query):
"""Process user query and return enhanced LLM-analyzed response"""
try:
# Use the enhanced crew with all tools
ticket_support_crew = EnhancedTicketSupportCrew().crew()
inputs = {'query': user_query}
crew_result = ticket_support_crew.kickoff(inputs=inputs)
# Get raw crew output
if hasattr(crew_result, 'raw'):
raw_response = crew_result.raw
else:
raw_response = str(crew_result)
return raw_response
except Exception as e:
return f"❌ Error processing query: {str(e)}\n\nPlease try again or check your query format."
def format_example_response(example_query):
"""Show what kind of response to expect for example queries"""
examples = {
"TKT-1024 details": "Will show: ticket number, status, severity, description, assignee, tags, dates",
"show me high severity tickets": "Will list: all high severity tickets with key details",
"tickets with backend tag": "Will find: tickets tagged with 'backend'",
"login error tickets": "Will search: tickets mentioning 'login error' in description"
}
return examples.get(example_query, "Will search the database based on your query type")
# Create the enhanced Gradio interface
with gr.Blocks(title="IT Support Intelligence Bot", theme=gr.themes.Soft()) as demo:
# Header with Tips expandable section
with gr.Row():
with gr.Column(scale=8):
gr.Markdown("# 🎯 Enhanced IT Ticket Support Intelligence")
with gr.Column(scale=2):
with gr.Accordion("πŸ’‘ Tips", open=False):
gr.Markdown("""
- Be specific in your queries for better results
- Use ticket numbers (TKT-XXXX) for exact matches
- Try different keywords if first search doesn't find what you need
- Check the Query Types Guide for more examples
""")
gr.Markdown("Search tickets by number, status, severity, tags, or keywords with our intelligent AI agent.")
gr.Markdown("Check the files for tickets.json to see tickets to query(TKT-1001 to 1050). The agents query the tickets.db database.")
gr.Markdown("README has a section of future vision of this app with more agents, tasks and tools.")
# Input section
with gr.Row():
with gr.Column(scale=4):
user_input = gr.Textbox(
label="πŸ” Enter your query",
lines=2,
max_lines=3,
placeholder="e.g., TKT-1024 details, show me high severity tickets, login error tickets"
)
with gr.Column(scale=1):
submit_button = gr.Button("πŸš€ Search", variant="primary", size="lg")
clear_button = gr.Button("πŸ—‘οΈ Clear", variant="secondary", size="sm")
# Main content: 50% Results, 50% Guides
with gr.Row(equal_height=True):
# Left half: Search Results (50%)
with gr.Column(scale=1):
gr.Markdown("### πŸ“‹ Search Results")
output_text = gr.Textbox(
label="",
interactive=False,
lines=20,
max_lines=25,
show_copy_button=True,
placeholder="Enter a query above and click Search to see results here..."
)
# Right half: Guides and Examples (50%)
with gr.Column(scale=1):
gr.Markdown("### πŸ“– Query Guide & Examples")
# Query type guide
with gr.Accordion("πŸ“– Query Types Guide", open=False):
gr.Markdown("""
### Supported Query Types:
**🎫 Specific Tickets:**
- `TKT-1024 details` - Get full details of a specific ticket
- `TKT-1024 who closed it` - Find who closed a ticket
- `TKT-1024 status` - Check ticket status
**πŸ“Š Status-based Searches:**
- `show me open tickets` - All open tickets
- `closed tickets` - Recently closed tickets
- `in progress tickets` - Currently active tickets
**⚠️ Severity-based Searches:**
- `high severity tickets` - Critical and high priority issues
- `show me critical tickets` - Most urgent tickets
- `low severity tickets` - Less urgent issues
**🏷️ Tag-based Searches:**
- `backend tickets` - Tickets tagged with 'backend'
- `API related tickets` - Tickets with API tag
- `database tickets` - Database-related issues
**πŸ” Keyword Searches:**
- `login error tickets` - Tickets mentioning login errors
- `payment processing issues` - Payment-related problems
- `database connection` - Connection issues
**πŸ‘€ Assignee Searches:**
- `tickets assigned to John` - Tickets for specific person
- `Victoria Garcia tickets` - Tickets assigned to Victoria
""")
# Example queries with categories
with gr.Accordion("πŸ’‘ Example Queries", open=True):
example_categories = {
"🎫 Specific Tickets": [
"TKT-1024 what does it say and who closed it?",
"TKT-1021 status and details",
"Show me ticket TKT-1050"
],
"πŸ“Š Status & Severity": [
"show me all open tickets",
"high severity tickets",
"critical tickets that are still open",
"recently closed tickets"
],
"🏷️ Tags & Categories": [
"tickets with backend tag",
"API related tickets",
"frontend tickets",
"database tagged tickets"
],
"πŸ” Keyword Search": [
"login error tickets",
"payment processing issues",
"database connection problems",
"broken CSS tickets"
]
}
for category, queries in example_categories.items():
gr.Markdown(f"**{category}:**")
for query in queries:
gr.Button(query, variant="outline", size="sm").click(
lambda q=query: q, outputs=user_input
)
# Statistics section (you can enhance this with real data)
with gr.Accordion("πŸ“ˆ Quick Stats", open=False):
gr.Markdown("""
**Database Overview:**
- 🎫 Total tickets in system
- 🟒 Open tickets
- πŸ”΄ High/Critical severity
- πŸ“Š Recent activity
*Connect to your database to show real-time statistics*
""")
# Event handlers
submit_button.click(process_query, inputs=user_input, outputs=output_text)
user_input.submit(process_query, inputs=user_input, outputs=output_text)
clear_button.click(lambda: ("", ""), outputs=[user_input, output_text])
# Launch the enhanced app
if __name__ == "__main__":
demo.launch()