File size: 1,892 Bytes
ea74d74
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import gradio as gr
from ocr_utils import process_image
from salesforce_utils import push_data_to_salesforce, fetch_inventory_data
from viz_utils import generate_stock_chart
import pandas as pd

uploaded_data = []

def handle_upload(image, mode, entry_type):
    global uploaded_data
    data = process_image(image)
    df = pd.DataFrame(data)
    uploaded_data = df
    return df

def update_salesforce(dataframe, mode, entry_type):
    df = pd.DataFrame(dataframe)
    status = push_data_to_salesforce(df, mode, entry_type)
    return status

def download_inventory():
    inventory = fetch_inventory_data()
    return inventory, inventory.to_csv(index=False)

def show_chart():
    df = fetch_inventory_data()
    chart_path = generate_stock_chart(df)
    return chart_path

with gr.Blocks() as demo:
    gr.Markdown("## πŸš€ Salesforce Inventory OCR App")
    with gr.Row():
        image = gr.Image(type="filepath", label="Upload Invoice or Label")
        mode = gr.Dropdown(["Entry", "Exit"], label="Select Mode")
        entry_type = gr.Dropdown(["Sales", "Non-Sales"], label="Entry Type")
    upload_btn = gr.Button("Extract & Show Data")
    table = gr.Dataframe(label="Editable Product Table", interactive=True)
    upload_btn.click(handle_upload, inputs=[image, mode, entry_type], outputs=table)

    update_btn = gr.Button("Update Salesforce")
    update_status = gr.Textbox(label="Update Status")
    update_btn.click(update_salesforce, inputs=[table, mode, entry_type], outputs=update_status)

    download_btn = gr.Button("Download Inventory from Salesforce")
    inventory_table = gr.Dataframe()
    csv_file = gr.File()
    download_btn.click(download_inventory, inputs=[], outputs=[inventory_table, csv_file])

    chart_btn = gr.Button("Visualize Stock Levels")
    chart_output = gr.Image()
    chart_btn.click(show_chart, inputs=[], outputs=chart_output)

demo.launch()