Download utils/query_engine.py from datawizard116/GenAI-Text2SQL-Analytics-Assistant: direct link, hf CLI and curl.
- Browser
- Download file 496 Bytes
-
https://huggingface.co/spaces/datawizard116/GenAI-Text2SQL-Analytics-Assistant/resolve/ab2708c859bc8ebe3a6d34cbe2e548a079c88a3e/utils/query_engine.py
- Command line
-
hf download hf://spaces/datawizard116/GenAI-Text2SQL-Analytics-Assistant@ab2708c859bc8ebe3a6d34cbe2e548a079c88a3e/utils/query_engine.py
-
curl -L -o query_engine.py https://huggingface.co/spaces/datawizard116/GenAI-Text2SQL-Analytics-Assistant/resolve/ab2708c859bc8ebe3a6d34cbe2e548a079c88a3e/utils/query_engine.py
496 Bytes
| import pandas as pd | |
| from sqlalchemy import create_engine, text | |
| engine = create_engine("sqlite:///database/ecommerce.db") | |
| def run_query(sql_query): | |
| try: | |
| with engine.connect() as connection: | |
| result = connection.execute(text(sql_query)) | |
| rows = result.fetchall() | |
| columns = result.keys() | |
| df = pd.DataFrame(rows, columns=columns) | |
| return df | |
| except Exception as e: | |
| return str(e) |