bhlewis commited on
Commit
f14f1f4
·
verified ·
1 Parent(s): 6744e1a

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +1 -28
app.py CHANGED
@@ -41,17 +41,6 @@ index.add(embeddings)
41
  # Load BERT model for encoding search queries
42
  model = SentenceTransformer('all-mpnet-base-v2')
43
 
44
- def exact_text_match(query, metadata):
45
- matches = []
46
- query_lower = query.lower()
47
- for patent_number, data in metadata.items():
48
- text = data.get('text', '')
49
- if isinstance(text, float):
50
- text = ''
51
- if query_lower in text.lower():
52
- matches.append((patent_number, 1.0)) # Score of 1.0 for exact match
53
- return matches
54
-
55
  def search(query, top_k=5):
56
  print(f"Searching for: {query}")
57
 
@@ -79,23 +68,7 @@ def search(query, top_k=5):
79
  result += f"Similarity Score: {distances[0][i]:.4f}\n\n"
80
  results.append(result)
81
 
82
- # Fallback to exact text match if no results or low similarity
83
- if not results or distances[0][0] < 0.5:
84
- print("Falling back to exact text match")
85
- exact_matches = exact_text_match(query, metadata)
86
- if exact_matches:
87
- print(f"Exact matches found: {exact_matches}")
88
- else:
89
- print("No exact matches found")
90
- for patent_number, score in exact_matches[:top_k]:
91
- patent_data = metadata[patent_number]
92
- result = f"Patent Number: {patent_number}\n"
93
- text = patent_data.get('text', 'No text available')
94
- result += f"Text: {text[:200]}...\n"
95
- result += f"Exact Match Score: {score:.4f}\n\n"
96
- results.append(result)
97
-
98
- return "\n".join(results)
99
 
100
  # Create Gradio interface
101
  iface = gr.Interface(
 
41
  # Load BERT model for encoding search queries
42
  model = SentenceTransformer('all-mpnet-base-v2')
43
 
 
 
 
 
 
 
 
 
 
 
 
44
  def search(query, top_k=5):
45
  print(f"Searching for: {query}")
46
 
 
68
  result += f"Similarity Score: {distances[0][i]:.4f}\n\n"
69
  results.append(result)
70
 
71
+ return "\n".join(results[:top_k])
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
72
 
73
  # Create Gradio interface
74
  iface = gr.Interface(