Update app.py
Browse files
app.py
CHANGED
|
@@ -1,32 +1,26 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
-
import pyodbc
|
| 3 |
import pandas as pd
|
| 4 |
from datetime import date
|
|
|
|
| 5 |
|
| 6 |
-
# Function to connect to SQL Server and run stored procedure
|
| 7 |
def run_procedure(server, database, username, password, start_date, end_date):
|
| 8 |
try:
|
| 9 |
-
#
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
df = pd.read_sql(
|
| 26 |
-
"SELECT * FROM [DocumentAcquisition].dbo.Temp_Document_Procurement_Timeline "
|
| 27 |
-
"WHERE Document_Procurement_Name = 'EQUITY'",
|
| 28 |
-
conn
|
| 29 |
-
)
|
| 30 |
|
| 31 |
if df.empty:
|
| 32 |
return "No data found for the given dates.", None
|
|
|
|
| 1 |
import gradio as gr
|
|
|
|
| 2 |
import pandas as pd
|
| 3 |
from datetime import date
|
| 4 |
+
import pymssql
|
| 5 |
|
|
|
|
| 6 |
def run_procedure(server, database, username, password, start_date, end_date):
|
| 7 |
try:
|
| 8 |
+
# Connect to SQL Server using pymssql (no ODBC required)
|
| 9 |
+
conn = pymssql.connect(server=server, user=username, password=password, database=database)
|
| 10 |
+
cursor = conn.cursor()
|
| 11 |
+
|
| 12 |
+
# Run the stored procedure with parameters
|
| 13 |
+
cursor.execute("EXEC dbo.Temp_Get_EQUITY_DocumentProcurement %s, %s", (start_date, end_date))
|
| 14 |
+
conn.commit()
|
| 15 |
+
|
| 16 |
+
# Now read the output table using pandas
|
| 17 |
+
query = """
|
| 18 |
+
SELECT * FROM [DocumentAcquisition].dbo.Temp_Document_Procurement_Timeline
|
| 19 |
+
WHERE Document_Procurement_Name = 'EQUITY'
|
| 20 |
+
"""
|
| 21 |
+
df = pd.read_sql(query, conn)
|
| 22 |
+
|
| 23 |
+
conn.close()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 24 |
|
| 25 |
if df.empty:
|
| 26 |
return "No data found for the given dates.", None
|