Yatheshr commited on
Commit
84d0ebf
·
verified ·
1 Parent(s): c8cf40f

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +9 -12
app.py CHANGED
@@ -1,16 +1,15 @@
1
  import gradio as gr
2
  import pandas as pd
3
- from datetime import date
4
- import pymssql
5
-
6
  from datetime import datetime
 
7
 
8
- start_date = datetime.strptime(start_date, "%Y-%m-%d").date()
9
- end_date = datetime.strptime(end_date, "%Y-%m-%d").date()
10
-
11
-
12
  def run_procedure(server, database, username, password, start_date, end_date):
13
  try:
 
 
 
 
14
  # Connect to SQL Server using pymssql (no ODBC required)
15
  conn = pymssql.connect(server=server, user=username, password=password, database=database)
16
  cursor = conn.cursor()
@@ -25,13 +24,11 @@ def run_procedure(server, database, username, password, start_date, end_date):
25
  WHERE Document_Procurement_Name = 'EQUITY'
26
  """
27
  df = pd.read_sql(query, conn)
28
-
29
  conn.close()
30
 
31
  if df.empty:
32
  return "No data found for the given dates.", None
33
  else:
34
- # Save to CSV
35
  csv_path = "document_procurement_report.csv"
36
  df.to_csv(csv_path, index=False)
37
  return df, csv_path
@@ -39,7 +36,7 @@ def run_procedure(server, database, username, password, start_date, end_date):
39
  except Exception as e:
40
  return f"Error: {str(e)}", None
41
 
42
- # Gradio UI
43
  iface = gr.Interface(
44
  fn=run_procedure,
45
  inputs=[
@@ -47,8 +44,8 @@ iface = gr.Interface(
47
  gr.Textbox(label="Database Name", placeholder="e.g., DocumentAcquisition"),
48
  gr.Textbox(label="Username"),
49
  gr.Textbox(label="Password", type="password"),
50
- gr.Date(label="Start Date", value=date(2024, 1, 1)),
51
- gr.Date(label="End Date", value=date(2024, 1, 7)),
52
  ],
53
  outputs=[
54
  gr.Dataframe(label="Procedure Output"),
 
1
  import gradio as gr
2
  import pandas as pd
 
 
 
3
  from datetime import datetime
4
+ import pymssql
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
+ # Convert string dates to datetime.date objects
10
+ start_date = datetime.strptime(start_date, "%Y-%m-%d").date()
11
+ end_date = datetime.strptime(end_date, "%Y-%m-%d").date()
12
+
13
  # Connect to SQL Server using pymssql (no ODBC required)
14
  conn = pymssql.connect(server=server, user=username, password=password, database=database)
15
  cursor = conn.cursor()
 
24
  WHERE Document_Procurement_Name = 'EQUITY'
25
  """
26
  df = pd.read_sql(query, conn)
 
27
  conn.close()
28
 
29
  if df.empty:
30
  return "No data found for the given dates.", None
31
  else:
 
32
  csv_path = "document_procurement_report.csv"
33
  df.to_csv(csv_path, index=False)
34
  return df, csv_path
 
36
  except Exception as e:
37
  return f"Error: {str(e)}", None
38
 
39
+ # Gradio UI using Textbox for dates (YYYY-MM-DD)
40
  iface = gr.Interface(
41
  fn=run_procedure,
42
  inputs=[
 
44
  gr.Textbox(label="Database Name", placeholder="e.g., DocumentAcquisition"),
45
  gr.Textbox(label="Username"),
46
  gr.Textbox(label="Password", type="password"),
47
+ gr.Textbox(label="Start Date (YYYY-MM-DD)", value="2024-01-01"),
48
+ gr.Textbox(label="End Date (YYYY-MM-DD)", value="2024-01-07"),
49
  ],
50
  outputs=[
51
  gr.Dataframe(label="Procedure Output"),