b3ndur commited on
Commit
1ce00f6
·
1 Parent(s): 5f1dc23
Files changed (1) hide show
  1. app.py +14 -3
app.py CHANGED
@@ -8,12 +8,24 @@ import sqlite3
8
  import pandas as pd
9
  from tqdm import tqdm
10
 
 
 
 
11
  # Get the Groq API key from environment variables
12
  client = Groq(
13
  api_key="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"
14
  )
15
 
16
 
 
 
 
 
 
 
 
 
 
17
  con = sqlite3.connect("file::memory:?cache=shared", check_same_thread=False)
18
  con.row_factory = sqlite3.Row
19
  cur = con.cursor()
@@ -47,12 +59,11 @@ if cur.fetchone() is None:
47
  )
48
  con.commit()
49
 
50
- # Compute and store embeddings
51
  def compute_and_store_embeddings():
52
- model = SentenceTransformer('paraphrase-MiniLM-L6-v2')
53
  cur.execute("SELECT Place_Id, Place_Name, Category, Description, City FROM places")
54
  places = cur.fetchall()
55
-
56
  for place in places:
57
  text = f"{place[1]} {place[2]} {place[3]} {place[4]}"
58
  embedding = model.encode(text)
 
8
  import pandas as pd
9
  from tqdm import tqdm
10
 
11
+ # Define the SentenceTransformer model globally
12
+ model = SentenceTransformer('paraphrase-MiniLM-L6-v2')
13
+
14
  # Get the Groq API key from environment variables
15
  client = Groq(
16
  api_key="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"
17
  )
18
 
19
 
20
+ # Generate user embedding using the globally defined model
21
+ def get_user_embedding(query):
22
+ try:
23
+ return model.encode(query)
24
+ except Exception as e:
25
+ print(f"Error generating embedding: {e}")
26
+ return np.zeros(384) # Return a zero-vector of the correct size if there is an error
27
+
28
+
29
  con = sqlite3.connect("file::memory:?cache=shared", check_same_thread=False)
30
  con.row_factory = sqlite3.Row
31
  cur = con.cursor()
 
59
  )
60
  con.commit()
61
 
62
+ # Compute and store embeddings for places using the same model
63
  def compute_and_store_embeddings():
 
64
  cur.execute("SELECT Place_Id, Place_Name, Category, Description, City FROM places")
65
  places = cur.fetchall()
66
+
67
  for place in places:
68
  text = f"{place[1]} {place[2]} {place[3]} {place[4]}"
69
  embedding = model.encode(text)