nileshhanotia commited on
Commit
e6c745f
·
verified ·
1 Parent(s): 9114dbb

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +8 -22
app.py CHANGED
@@ -8,41 +8,28 @@ class UnifiedSystem:
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/" # Shopify base URL for product links
12
-
13
  def process_query(self, query):
14
  intent, confidence = self.intent_classifier.classify(query)
15
-
16
  if intent == "database_query":
17
- # Generate SQL query and fetch Shopify data for database queries
18
  sql_query = self.sql_generator.generate_query(query)
19
  products = self.sql_generator.fetch_shopify_data("products")
20
-
21
  if products and 'products' in products:
22
  results = "\n".join([
23
- f"Title: {p['title']}, Vendor: {p['vendor']}, "
24
- f"Link: {self.base_url}{p['handle']}"
25
  for p in products['products']
26
  ])
27
  return f"Intent: Database Query (Confidence: {confidence:.2f})\n\n" \
28
  f"SQL Query: {sql_query}\n\nResults:\n{results}"
29
  else:
30
  return "No results found or error fetching data from Shopify."
31
-
32
  elif intent == "product_description":
33
- # Retrieve product description and relevant handles from RAGSystem
34
  rag_response = self.rag_system.process_query(query)
35
-
36
- # Assuming `rag_response` now includes a list of dictionaries with 'description' and 'handle' keys
37
- if rag_response and 'products' in rag_response:
38
- results = "\n".join([
39
- f"Description: {p['description']}, Link: {self.base_url}{p['handle']}"
40
- for p in rag_response['products']
41
- ])
42
- return f"Intent: Product Description (Confidence: {confidence:.2f})\n\n" \
43
- f"Response:\n{results}"
44
- else:
45
- return "No matching products found for the description query."
46
 
47
  return "Intent not recognized."
48
 
@@ -52,8 +39,7 @@ def create_interface():
52
  examples = [
53
  "Show me shirt less than 5 USD",
54
  "Show me shirt with red color",
55
- "Show me T-shirt with M size",
56
- "Describe the features of the blue jeans"
57
  ]
58
 
59
  iface = gr.Interface(
 
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']}"
 
22
  for p in products['products']
23
  ])
24
  return f"Intent: Database Query (Confidence: {confidence:.2f})\n\n" \
25
  f"SQL Query: {sql_query}\n\nResults:\n{results}"
26
  else:
27
  return "No results found or error fetching data from Shopify."
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
 
34
  return "Intent not recognized."
35
 
 
39
  examples = [
40
  "Show me shirt less than 5 USD",
41
  "Show me shirt with red color",
42
+ "Show me T-shirt with M size"
 
43
  ]
44
 
45
  iface = gr.Interface(