File size: 2,039 Bytes
950ab78
56c1423
c8cf40f
84d0ebf
c8cf40f
84d0ebf
56c1423
 
84d0ebf
 
 
7936ccc
 
 
 
950ab78
7936ccc
 
 
 
 
 
045f4e9
56c1423
e20c1b7
56c1423
 
 
e20c1b7
950ab78
56c1423
e20c1b7
56c1423
e20c1b7
56c1423
 
6cfdb57
56c1423
 
 
 
84d0ebf
 
6cfdb57
045f4e9
56c1423
 
e20c1b7
045f4e9
56c1423
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
import gradio as gr
import pandas as pd
from datetime import datetime
import pymssql

# Function to connect to SQL Server and run stored procedure
def run_procedure(server, database, username, password, start_date, end_date):
    try:
        start_date = datetime.strptime(start_date, "%Y-%m-%d").date()
        end_date = datetime.strptime(end_date, "%Y-%m-%d").date()

        conn = pymssql.connect(server=server, user=username, password=password, database=database)
        cursor = conn.cursor()
        cursor.execute("EXEC dbo.Temp_Get_EQUITY_DocumentProcurement %s, %s", (start_date, end_date))
        conn.commit()

        query = """
            SELECT * FROM [DocumentAcquisition].dbo.Temp_Document_Procurement_Timeline
            WHERE Document_Procurement_Name = 'EQUITY'
        """
        df = pd.read_sql(query, conn)
        conn.close()

        if df.empty:
            return None, None, "No data found for the given dates."
        else:
            csv_path = "document_procurement_report.csv"
            df.to_csv(csv_path, index=False)
            return df, csv_path, "Success"

    except Exception as e:
        return None, None, f"Error: {str(e)}"

# Updated Gradio UI
iface = gr.Interface(
    fn=run_procedure,
    inputs=[
        gr.Textbox(label="Server Name", placeholder="e.g., myserver.database.windows.net"),
        gr.Textbox(label="Database Name", placeholder="e.g., DocumentAcquisition"),
        gr.Textbox(label="Username"),
        gr.Textbox(label="Password", type="password"),
        gr.Textbox(label="Start Date (YYYY-MM-DD)", value="2024-01-01"),
        gr.Textbox(label="End Date (YYYY-MM-DD)", value="2024-01-07"),
    ],
    outputs=[
        gr.Dataframe(label="Procedure Output"),
        gr.File(label="Download CSV Report"),
        gr.Textbox(label="Status / Error Message")
    ],
    title="EQUITY Document Procurement Report Generator",
    description="Enter your SQL Server details and date range to run the stored procedure and download the report."
)

iface.launch()