Update app.py
Browse files
app.py
CHANGED
|
@@ -7,6 +7,9 @@ import gradio as gr
|
|
| 7 |
import numpy as np
|
| 8 |
import time
|
| 9 |
import os
|
|
|
|
|
|
|
|
|
|
| 10 |
#import pkg_resources
|
| 11 |
|
| 12 |
'''
|
|
@@ -18,6 +21,38 @@ for package, version in installed_packages.items():
|
|
| 18 |
print(f"{package}=={version}")
|
| 19 |
'''
|
| 20 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 21 |
# Load the chatbot model
|
| 22 |
chatbot_model_name = "microsoft/DialoGPT-medium"
|
| 23 |
tokenizer = AutoTokenizer.from_pretrained(chatbot_model_name)
|
|
@@ -28,19 +63,13 @@ sql_model_name = "microsoft/tapex-large-finetuned-wtq"
|
|
| 28 |
sql_tokenizer = TapexTokenizer.from_pretrained(sql_model_name)
|
| 29 |
sql_model = BartForConditionalGeneration.from_pretrained(sql_model_name)
|
| 30 |
|
| 31 |
-
|
| 32 |
-
"year": [1896, 1900, 1904, 2004, 2008, 2012],
|
| 33 |
-
"city": ["athens", "paris", "st. louis", "athens", "beijing", "london"]
|
| 34 |
-
}
|
| 35 |
-
table = pd.DataFrame.from_dict(data)
|
| 36 |
-
|
| 37 |
-
sql_response = None
|
| 38 |
|
| 39 |
def predict(input, history=[]):
|
| 40 |
|
| 41 |
-
global sql_response
|
| 42 |
# Check if the user input is a question
|
| 43 |
-
is_question = "?" in input
|
| 44 |
|
| 45 |
'''
|
| 46 |
if is_question:
|
|
|
|
| 7 |
import numpy as np
|
| 8 |
import time
|
| 9 |
import os
|
| 10 |
+
|
| 11 |
+
import pyodbc
|
| 12 |
+
|
| 13 |
#import pkg_resources
|
| 14 |
|
| 15 |
'''
|
|
|
|
| 21 |
print(f"{package}=={version}")
|
| 22 |
'''
|
| 23 |
|
| 24 |
+
'''
|
| 25 |
+
# Replace the connection parameters with your SQL Server information
|
| 26 |
+
server = 'your_server'
|
| 27 |
+
database = 'your_database'
|
| 28 |
+
username = 'your_username'
|
| 29 |
+
password = 'your_password'
|
| 30 |
+
driver = 'SQL Server' # This depends on the ODBC driver installed on your system
|
| 31 |
+
|
| 32 |
+
# Create the connection string
|
| 33 |
+
connection_string = f'DRIVER={{{driver}}};SERVER={server};DATABASE={database};UID={username};PWD={password}'
|
| 34 |
+
|
| 35 |
+
# Connect to the SQL Server
|
| 36 |
+
conn = pyodbc.connect(connection_string)
|
| 37 |
+
|
| 38 |
+
#============================================================================
|
| 39 |
+
# Replace "your_query" with your SQL query to fetch data from the database
|
| 40 |
+
query = 'SELECT * FROM your_table_name'
|
| 41 |
+
|
| 42 |
+
# Use pandas to read data from the SQL Server and store it in a DataFrame
|
| 43 |
+
df = pd.read_sql_query(query, conn)
|
| 44 |
+
|
| 45 |
+
# Close the SQL connection
|
| 46 |
+
conn.close()
|
| 47 |
+
'''
|
| 48 |
+
|
| 49 |
+
data = {
|
| 50 |
+
"year": [1896, 1900, 1904, 2004, 2008, 2012],
|
| 51 |
+
"city": ["athens", "paris", "st. louis", "athens", "beijing", "london"]
|
| 52 |
+
}
|
| 53 |
+
table = pd.DataFrame.from_dict(data)
|
| 54 |
+
|
| 55 |
+
|
| 56 |
# Load the chatbot model
|
| 57 |
chatbot_model_name = "microsoft/DialoGPT-medium"
|
| 58 |
tokenizer = AutoTokenizer.from_pretrained(chatbot_model_name)
|
|
|
|
| 63 |
sql_tokenizer = TapexTokenizer.from_pretrained(sql_model_name)
|
| 64 |
sql_model = BartForConditionalGeneration.from_pretrained(sql_model_name)
|
| 65 |
|
| 66 |
+
#sql_response = None
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 67 |
|
| 68 |
def predict(input, history=[]):
|
| 69 |
|
| 70 |
+
#global sql_response
|
| 71 |
# Check if the user input is a question
|
| 72 |
+
#is_question = "?" in input
|
| 73 |
|
| 74 |
'''
|
| 75 |
if is_question:
|