-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.py
More file actions
30 lines (26 loc) · 947 Bytes
/
Copy pathapp.py
File metadata and controls
30 lines (26 loc) · 947 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
import streamlit as st
from llm_sql import nl_to_sql, is_safe_sql
from db_config import get_connection
from hybrid_search import semantic_product_search
st.set_page_config(page_title="NL Database Search", layout="wide")
st.title("🔍 Natural Language Database Search")
query = st.text_input("Ask your question")
if st.button("Search"):
if "similar" in query.lower() or "related" in query.lower():
results = semantic_product_search(query)
st.write("### Semantic Search Results")
st.table(results)
else:
sql = nl_to_sql(query)
st.code(sql, language="sql")
if is_safe_sql(sql):
conn = get_connection()
cur = conn.cursor()
cur.execute(sql)
rows = cur.fetchall()
st.write("### Query Results")
st.table(rows)
cur.close()
conn.close()
else:
st.error("❌ Unsafe SQL detected")