Yatheshr commited on
Commit
7936ccc
·
verified ·
1 Parent(s): bff2c02

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +17 -23
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
- # Create connection string
10
- conn_str = (
11
- f"DRIVER={{SQL Server Native Client 11.0}};"
12
- f"SERVER={server};"
13
- f"DATABASE={database};"
14
- f"UID={username};"
15
- f"PWD={password}"
16
- )
17
- with pyodbc.connect(conn_str) as conn:
18
- cursor = conn.cursor()
19
-
20
- # Execute stored procedure
21
- cursor.execute("EXEC dbo.Temp_Get_EQUITY_DocumentProcurement ?, ?", start_date, end_date)
22
- conn.commit()
23
-
24
- # Fetch the output data from the timeline table
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