asynchronousai commited on
Commit
8225dde
·
verified ·
1 Parent(s): 8e540e5

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +8 -1
app.py CHANGED
@@ -1,7 +1,14 @@
1
  from vectordb import Memory
2
  import gradio as gr
3
  import json
 
4
 
 
 
 
 
 
 
5
  def process_json(json_input):
6
  try:
7
  input = json.loads(json_input)
@@ -11,7 +18,7 @@ def process_json(json_input):
11
 
12
  results = memory.search(input['prompt'], top_n=input['topN'])
13
 
14
- return json.dumps(results, indent=4)
15
  except json.JSONDecodeError:
16
  return "Invalid JSON input."
17
 
 
1
  from vectordb import Memory
2
  import gradio as gr
3
  import json
4
+ import numpy as np
5
 
6
+ class CustomEncoder(json.JSONEncoder):
7
+ def default(self, obj):
8
+ if isinstance(obj, np.float32):
9
+ return float(obj) # Convert float32 to native float
10
+ return super().default(obj)
11
+
12
  def process_json(json_input):
13
  try:
14
  input = json.loads(json_input)
 
18
 
19
  results = memory.search(input['prompt'], top_n=input['topN'])
20
 
21
+ return json.dumps(results, indent=4, cls=CustomEncoder)
22
  except json.JSONDecodeError:
23
  return "Invalid JSON input."
24