Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -2,14 +2,18 @@ import gradio as gr
|
|
2 |
from sql_generator import SQLGenerator
|
3 |
from intent_classifier import IntentClassifier
|
4 |
from rag_system import RAGSystem
|
|
|
5 |
|
6 |
class UnifiedSystem:
|
7 |
def __init__(self):
|
8 |
self.sql_generator = SQLGenerator()
|
9 |
self.intent_classifier = IntentClassifier()
|
10 |
self.rag_system = RAGSystem()
|
11 |
-
|
|
|
|
|
12 |
def process_query(self, query):
|
|
|
13 |
intent, confidence = self.intent_classifier.classify(query)
|
14 |
|
15 |
if intent == "database_query":
|
@@ -32,6 +36,9 @@ class UnifiedSystem:
|
|
32 |
f"Response: {rag_response}"
|
33 |
|
34 |
return "Intent not recognized."
|
|
|
|
|
|
|
35 |
|
36 |
def create_interface():
|
37 |
system = UnifiedSystem()
|
@@ -44,11 +51,19 @@ def create_interface():
|
|
44 |
),
|
45 |
outputs=gr.Textbox(label="Response"),
|
46 |
title="Unified Query Processing System",
|
47 |
-
description="Enter a natural language query to search products or get descriptions."
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
48 |
)
|
49 |
|
50 |
return iface
|
51 |
|
52 |
if __name__ == "__main__":
|
53 |
iface = create_interface()
|
54 |
-
iface.launch()
|
|
|
2 |
from sql_generator import SQLGenerator
|
3 |
from intent_classifier import IntentClassifier
|
4 |
from rag_system import RAGSystem
|
5 |
+
import threading
|
6 |
|
7 |
class UnifiedSystem:
|
8 |
def __init__(self):
|
9 |
self.sql_generator = SQLGenerator()
|
10 |
self.intent_classifier = IntentClassifier()
|
11 |
self.rag_system = RAGSystem()
|
12 |
+
self.current_query_thread = None # To keep track of the current query thread
|
13 |
+
self.stop_event = threading.Event() # Event to stop the current process
|
14 |
+
|
15 |
def process_query(self, query):
|
16 |
+
self.stop_event.clear() # Clear the stop event
|
17 |
intent, confidence = self.intent_classifier.classify(query)
|
18 |
|
19 |
if intent == "database_query":
|
|
|
36 |
f"Response: {rag_response}"
|
37 |
|
38 |
return "Intent not recognized."
|
39 |
+
|
40 |
+
def stop_query(self):
|
41 |
+
self.stop_event.set() # Set the event to stop the current process
|
42 |
|
43 |
def create_interface():
|
44 |
system = UnifiedSystem()
|
|
|
51 |
),
|
52 |
outputs=gr.Textbox(label="Response"),
|
53 |
title="Unified Query Processing System",
|
54 |
+
description="Enter a natural language query to search products or get descriptions.",
|
55 |
+
live=False # Live updates are not needed for this scenario
|
56 |
+
)
|
57 |
+
|
58 |
+
# Add a button to stop the current query
|
59 |
+
iface.add_button(
|
60 |
+
"Kill Query",
|
61 |
+
lambda: system.stop_query(),
|
62 |
+
elem_id="stop-button"
|
63 |
)
|
64 |
|
65 |
return iface
|
66 |
|
67 |
if __name__ == "__main__":
|
68 |
iface = create_interface()
|
69 |
+
iface.launch()
|