Spaces:
Running
Running
Commit
•
d872a02
1
Parent(s):
ce0d80f
fix: avoid while loop
Browse files
app.py
CHANGED
@@ -1,5 +1,3 @@
|
|
1 |
-
import time
|
2 |
-
|
3 |
import duckdb
|
4 |
import gradio as gr
|
5 |
import polars as pl
|
@@ -63,23 +61,21 @@ def vectorize_dataset(split: str, column: str):
|
|
63 |
|
64 |
|
65 |
def run_query(query: str, column: str):
|
66 |
-
|
67 |
-
|
68 |
-
|
69 |
-
|
70 |
-
|
71 |
-
|
72 |
-
|
73 |
-
|
74 |
-
|
75 |
-
|
76 |
-
|
77 |
-
|
78 |
-
|
79 |
-
|
80 |
-
""
|
81 |
-
).to_df()
|
82 |
-
return gr.Dataframe(df_results, visible=True)
|
83 |
|
84 |
|
85 |
def hide_components():
|
|
|
|
|
|
|
1 |
import duckdb
|
2 |
import gradio as gr
|
3 |
import polars as pl
|
|
|
61 |
|
62 |
|
63 |
def run_query(query: str, column: str):
|
64 |
+
try:
|
65 |
+
global df
|
66 |
+
|
67 |
+
vector = model.encode(query)
|
68 |
+
df_results = duckdb.sql(
|
69 |
+
query=f"""
|
70 |
+
SELECT *
|
71 |
+
FROM df
|
72 |
+
ORDER BY array_cosine_distance({column}_embeddings, {vector.tolist()}::FLOAT[256])
|
73 |
+
LIMIT 5
|
74 |
+
"""
|
75 |
+
).to_df()
|
76 |
+
return gr.Dataframe(df_results, visible=True)
|
77 |
+
except Exception as e:
|
78 |
+
raise gr.Error(f"Error running query: {e}")
|
|
|
|
|
79 |
|
80 |
|
81 |
def hide_components():
|