nileshhanotia commited on
Commit
bbdfa1c
·
verified ·
1 Parent(s): 215a74a

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +5 -30
app.py CHANGED
@@ -1,35 +1,21 @@
1
- # main.py
2
  import gradio as gr
3
  from sql_generator import SQLGenerator
4
  from intent_classifier import IntentClassifier
5
  from rag_system import RAGSystem
6
- import time
7
 
8
  class UnifiedSystem:
9
  def __init__(self):
10
  self.sql_generator = SQLGenerator()
11
  self.intent_classifier = IntentClassifier()
12
  self.rag_system = RAGSystem()
13
- self.stop_processing = False # Flag to stop processing
14
-
15
- def stop_query(self):
16
- self.stop_processing = True # Set the flag to stop processing
17
 
18
  def process_query(self, query):
19
- self.stop_processing = False # Reset the stop flag
20
  intent, confidence = self.intent_classifier.classify(query)
21
 
22
  if intent == "database_query":
23
  sql_query = self.sql_generator.generate_query(query)
24
  products = self.sql_generator.fetch_shopify_data("products")
25
 
26
- # Simulating long processing time
27
- time.sleep(2) # Replace this with actual processing logic
28
-
29
- # Check if the process has been stopped
30
- if self.stop_processing:
31
- return "Query processing was stopped by the user."
32
-
33
  if products and 'products' in products:
34
  results = "\n".join([
35
  f"Title: {p['title']}, Vendor: {p['vendor']}"
@@ -42,11 +28,6 @@ class UnifiedSystem:
42
 
43
  elif intent == "product_description":
44
  rag_response = self.rag_system.process_query(query)
45
-
46
- # Check if the process has been stopped
47
- if self.stop_processing:
48
- return "Query processing was stopped by the user."
49
-
50
  return f"Intent: Product Description (Confidence: {confidence:.2f})\n\n" \
51
  f"Response: {rag_response}"
52
 
@@ -57,23 +38,17 @@ def create_interface():
57
 
58
  iface = gr.Interface(
59
  fn=system.process_query,
60
- inputs=[
61
- gr.Textbox(
62
- label="Enter your query",
63
- placeholder="e.g., 'Show me all T-shirts' or 'Describe the product features'"
64
- ),
65
- gr.Button("Stop Processing") # Add a button to stop the process
66
- ],
67
  outputs=gr.Textbox(label="Response"),
68
  title="Unified Query Processing System",
69
  description="Enter a natural language query to search products or get descriptions."
70
  )
71
 
72
- # Bind the stop_query method to the button
73
- iface.add_event("Stop Processing", system.stop_query)
74
-
75
  return iface
76
 
77
  if __name__ == "__main__":
78
  iface = create_interface()
79
- iface.launch(share=True) # Set share=True to create a public link
 
 
1
  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":
16
  sql_query = self.sql_generator.generate_query(query)
17
  products = self.sql_generator.fetch_shopify_data("products")
18
 
 
 
 
 
 
 
 
19
  if products and 'products' in products:
20
  results = "\n".join([
21
  f"Title: {p['title']}, Vendor: {p['vendor']}"
 
28
 
29
  elif intent == "product_description":
30
  rag_response = self.rag_system.process_query(query)
 
 
 
 
 
31
  return f"Intent: Product Description (Confidence: {confidence:.2f})\n\n" \
32
  f"Response: {rag_response}"
33
 
 
38
 
39
  iface = gr.Interface(
40
  fn=system.process_query,
41
+ inputs=gr.Textbox(
42
+ label="Enter your query",
43
+ placeholder="e.g., 'Show me all T-shirts' or 'Describe the product features'"
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(