Spaces:
Runtime error
Runtime error
Download Text2sql.py from ankit75100/Ankit: direct link, hf CLI and curl.
- Browser
- Download file 1.06 kB
-
https://huggingface.co/spaces/ankit75100/Ankit/resolve/main/Text2sql.py
- Command line
-
hf download hf://spaces/ankit75100/Ankit/Text2sql.py
-
curl -L -o Text2sql.py https://huggingface.co/spaces/ankit75100/Ankit/resolve/main/Text2sql.py
1.06 kB
| from huggingface_hub import HfFileSystem | |
| fs = HfFileSystem() | |
| from langchain import HuggingFaceHub | |
| from langchain import SQLDatabase | |
| from langchain_experimental.sql.base import SQLDatabaseSequentialChain | |
| from langchain_experimental.sql import SQLDatabaseChain | |
| import json | |
| import os | |
| overal_temperature = 0.2 | |
| os.environ["HUGGINGFACEHUB_API_TOKEN"] = "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" | |
| llm = HuggingFaceHub(repo_id="juierror/flan-t5-text2sql-with-schema-v2", | |
| model_kwargs={"temperature":overal_temperature, | |
| "max_new_tokens":200} | |
| ) | |
| sqlite_db_path = "hf://datasets/ankit75100/Ankit/test_db.db" | |
| db1 = SQLDatabase.from_uri(f"sqlite:///{sqlite_db_path}") | |
| include_tables=['Employee','Album','Artist','Customer'], | |
| db_chain = SQLDatabaseChain.from_llm(llm, db1, verbose=True, return_direct=True) | |
| #user_input = input("Enter something: ") | |
| #datbase=db_chain.run(user_input) | |
| #print(datbase) | |
| def process_input(input_text): | |
| Result=db_chain.run(input_text) | |
| return Result | |