nileshhanotia commited on
Commit
fdb160a
·
verified ·
1 Parent(s): e258431

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +14 -22
app.py CHANGED
@@ -8,7 +8,8 @@ class UnifiedSystem:
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
 
@@ -17,9 +18,8 @@ class UnifiedSystem:
17
  products = self.sql_generator.fetch_shopify_data("products")
18
 
19
  if products and 'products' in products:
20
- base_url = "https://agkd0n-fa.myshopify.com/products/"
21
  results = "\n".join([
22
- f"Title: {p['title']}, Vendor: {p['vendor']}, Link: {base_url}{p['handle']}"
23
  for p in products['products']
24
  ])
25
  return f"Intent: Database Query (Confidence: {confidence:.2f})\n\n" \
@@ -28,32 +28,20 @@ class UnifiedSystem:
28
  return "No results found or error fetching data from Shopify."
29
 
30
  elif intent == "product_description":
31
- # Assuming the RAGSystem can return relevant product information
32
  rag_response = self.rag_system.process_query(query)
33
- description = rag_response.get("description", "No description available.")
34
- # Assuming you can fetch product handles relevant to the description
35
- handles = rag_response.get("handles", [])
36
- base_url = "https://agkd0n-fa.myshopify.com/products/"
37
 
38
- # Generate links for each handle
39
- handle_links = "\n".join([f"Link: {base_url}{handle}" for handle in handles])
40
-
41
- return (f"Intent: Product Description (Confidence: {confidence:.2f})\n\n"
42
- f"Response: {description}\n\n"
43
- f"Relevant Product Links:\n{handle_links}" if handles else "No relevant product links available.")
44
 
45
  return "Intent not recognized."
46
 
47
  def create_interface():
48
  system = UnifiedSystem()
49
 
50
- examples = [
51
- "Show me shirt less than 5 USD",
52
- "Show me shirt with red color",
53
- "Show me T-shirt with M size",
54
- "Describe the features of the blue jeans"
55
- ]
56
-
57
  iface = gr.Interface(
58
  fn=system.process_query,
59
  inputs=gr.Textbox(
@@ -63,7 +51,11 @@ def create_interface():
63
  outputs=gr.Textbox(label="Response"),
64
  title="Unified Query Processing System",
65
  description="Enter a natural language query to search products or get descriptions.",
66
- examples=examples
 
 
 
 
67
  )
68
 
69
  return iface
 
8
  self.sql_generator = SQLGenerator()
9
  self.intent_classifier = IntentClassifier()
10
  self.rag_system = RAGSystem()
11
+ self.base_url = "https://agkd0n-fa.myshopify.com/products/"
12
+
13
  def process_query(self, query):
14
  intent, confidence = self.intent_classifier.classify(query)
15
 
 
18
  products = self.sql_generator.fetch_shopify_data("products")
19
 
20
  if products and 'products' in products:
 
21
  results = "\n".join([
22
+ f"Title: {p['title']}, Vendor: {p['vendor']}, URL: {self.base_url}{p['handle']}"
23
  for p in products['products']
24
  ])
25
  return f"Intent: Database Query (Confidence: {confidence:.2f})\n\n" \
 
28
  return "No results found or error fetching data from Shopify."
29
 
30
  elif intent == "product_description":
 
31
  rag_response = self.rag_system.process_query(query)
32
+ # Assume the RAG system can return product handles for links
33
+ product_handles = rag_response.get('product_handles', [])
34
+ urls = [f"{self.base_url}{handle}" for handle in product_handles]
35
+ response = rag_response.get('response', "No description available.")
36
 
37
+ return f"Intent: Product Description (Confidence: {confidence:.2f})\n\n" \
38
+ f"Response: {response}\n\nProduct URLs:\n" + "\n".join(urls)
 
 
 
 
39
 
40
  return "Intent not recognized."
41
 
42
  def create_interface():
43
  system = UnifiedSystem()
44
 
 
 
 
 
 
 
 
45
  iface = gr.Interface(
46
  fn=system.process_query,
47
  inputs=gr.Textbox(
 
51
  outputs=gr.Textbox(label="Response"),
52
  title="Unified Query Processing System",
53
  description="Enter a natural language query to search products or get descriptions.",
54
+ examples=[
55
+ ["Show me shirts less than 5 USD"],
56
+ ["Show me shirts with red color"],
57
+ ["Show me T-shirts with M size"]
58
+ ]
59
  )
60
 
61
  return iface