Spaces:
Runtime error
Runtime error
Commit
·
c096dfe
1
Parent(s):
e419399
Create Text2sql.py
Browse files- Text2sql.py +26 -0
Text2sql.py
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from langchain import HuggingFaceHub
|
| 2 |
+
from langchain import SQLDatabase
|
| 3 |
+
from langchain_experimental.sql.base import SQLDatabaseSequentialChain
|
| 4 |
+
from langchain_experimental.sql import SQLDatabaseChain
|
| 5 |
+
import json
|
| 6 |
+
import os
|
| 7 |
+
overal_temperature = 0.2
|
| 8 |
+
os.environ["HUGGINGFACEHUB_API_TOKEN"] = "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"
|
| 9 |
+
llm = HuggingFaceHub(repo_id="juierror/flan-t5-text2sql-with-schema-v2",
|
| 10 |
+
model_kwargs={"temperature":overal_temperature,
|
| 11 |
+
"max_new_tokens":200}
|
| 12 |
+
)
|
| 13 |
+
sqlite_db_path = "C:/Users/ankitkumar.singh/Desktop/streamlit/test_db.db"
|
| 14 |
+
db1 = SQLDatabase.from_uri(f"sqlite:///{sqlite_db_path}")
|
| 15 |
+
include_tables=['Employee','Album','Artist','Customer'],
|
| 16 |
+
db_chain = SQLDatabaseChain.from_llm(llm, db1, verbose=True, return_direct=True)
|
| 17 |
+
#user_input = input("Enter something: ")
|
| 18 |
+
#datbase=db_chain.run(user_input)
|
| 19 |
+
#print(datbase)
|
| 20 |
+
def process_input(input_text):
|
| 21 |
+
|
| 22 |
+
Result=db_chain.run(input_text)
|
| 23 |
+
return Result
|
| 24 |
+
|
| 25 |
+
|
| 26 |
+
|