File size: 8,312 Bytes
b9b4639
 
 
 
 
61620ed
b9b4639
 
 
 
 
 
 
 
61620ed
b9b4639
 
 
 
61620ed
b9b4639
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
6eadf91
b9b4639
 
 
 
 
 
 
 
 
 
 
 
 
 
61620ed
6eadf91
b9b4639
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
61620ed
b9b4639
 
 
 
61620ed
b9b4639
 
 
 
61620ed
b9b4639
 
 
 
61620ed
b9b4639
 
 
 
61620ed
b9b4639
 
 
 
61620ed
b9b4639
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
61620ed
b9b4639
 
 
 
 
 
 
 
 
 
286166b
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
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()