Mubbashir Ahmed
commited on
Commit
·
480a83d
1
Parent(s):
041c831
code updaed
Browse files- app.py +8 -13
- requirements.txt +1 -1
app.py
CHANGED
|
@@ -1,7 +1,7 @@
|
|
| 1 |
import os
|
| 2 |
import gradio as gr
|
| 3 |
from huggingface_hub import InferenceClient
|
| 4 |
-
import
|
| 5 |
|
| 6 |
# Clients for each model provider
|
| 7 |
llama_client = InferenceClient(provider="sambanova", api_key=os.environ["HF_TOKEN"])
|
|
@@ -11,26 +11,21 @@ mistral_client = InferenceClient(provider="together", api_key=os.environ["HF_TOK
|
|
| 11 |
# Global objects
|
| 12 |
db_connection = None
|
| 13 |
|
| 14 |
-
def
|
| 15 |
server = os.getenv("SQL_SERVER")
|
| 16 |
database = os.getenv("SQL_DATABASE")
|
| 17 |
username = os.getenv("SQL_USERNAME")
|
| 18 |
password = os.getenv("SQL_PASSWORD")
|
| 19 |
|
| 20 |
-
|
| 21 |
-
f"Driver={{ODBC Driver 17 for SQL Server}};"
|
| 22 |
-
f"Server={server};"
|
| 23 |
-
f"Database={database};"
|
| 24 |
-
f"UID={username};"
|
| 25 |
-
f"PWD={password};"
|
| 26 |
-
)
|
| 27 |
|
| 28 |
try:
|
| 29 |
-
|
| 30 |
-
|
|
|
|
| 31 |
return conn
|
| 32 |
except Exception as e:
|
| 33 |
-
print(f"❌
|
| 34 |
return None
|
| 35 |
|
| 36 |
def get_sql_connection():
|
|
@@ -45,7 +40,7 @@ def get_sql_connection():
|
|
| 45 |
db_connection = None # reset if broken
|
| 46 |
|
| 47 |
# Reconnect if needed
|
| 48 |
-
db_connection =
|
| 49 |
return db_connection
|
| 50 |
|
| 51 |
# Format chat history for Markdown display
|
|
|
|
| 1 |
import os
|
| 2 |
import gradio as gr
|
| 3 |
from huggingface_hub import InferenceClient
|
| 4 |
+
from sqlalchemy import create_engine
|
| 5 |
|
| 6 |
# Clients for each model provider
|
| 7 |
llama_client = InferenceClient(provider="sambanova", api_key=os.environ["HF_TOKEN"])
|
|
|
|
| 11 |
# Global objects
|
| 12 |
db_connection = None
|
| 13 |
|
| 14 |
+
def get_sqlalchemy_connection():
|
| 15 |
server = os.getenv("SQL_SERVER")
|
| 16 |
database = os.getenv("SQL_DATABASE")
|
| 17 |
username = os.getenv("SQL_USERNAME")
|
| 18 |
password = os.getenv("SQL_PASSWORD")
|
| 19 |
|
| 20 |
+
connection_url = f"mssql+pymssql://{username}:{password}@{server}/{database}"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 21 |
|
| 22 |
try:
|
| 23 |
+
engine = create_engine(connection_url)
|
| 24 |
+
conn = engine.connect()
|
| 25 |
+
print("✅ SQLAlchemy + pymssql connection successful")
|
| 26 |
return conn
|
| 27 |
except Exception as e:
|
| 28 |
+
print(f"❌ SQLAlchemy connection failed: {e}")
|
| 29 |
return None
|
| 30 |
|
| 31 |
def get_sql_connection():
|
|
|
|
| 40 |
db_connection = None # reset if broken
|
| 41 |
|
| 42 |
# Reconnect if needed
|
| 43 |
+
db_connection = get_sqlalchemy_connection()
|
| 44 |
return db_connection
|
| 45 |
|
| 46 |
# Format chat history for Markdown display
|
requirements.txt
CHANGED
|
@@ -2,4 +2,4 @@ transformers>=4.41.0
|
|
| 2 |
torch>=2.2.0
|
| 3 |
gradio>=4.24.0
|
| 4 |
huggingface_hub>=0.22.2
|
| 5 |
-
|
|
|
|
| 2 |
torch>=2.2.0
|
| 3 |
gradio>=4.24.0
|
| 4 |
huggingface_hub>=0.22.2
|
| 5 |
+
sqlalchemy>=2.0.41
|