mode / app.py
qwekuaryee's picture
Update app.py
1fc8a58 verified
import pandas as pd
import gradio as gr
#import openpyxl
def compute_mode_openmarket(file):
# Read the Excel file
df = pd.read_excel(file)
opm=df[df['Outlet Channel']=='OPEN MARKET']
# Compute the mode of each column
modes = opm.mode()
# Convert the result to a new Excel file
modes.to_excel("modes.xlsx", index=False)
return "modes.xlsx"
def compute_mode_wholesale(file):
# Read the Excel file
df = pd.read_excel(file)
wholesale=df[df['Outlet Channel']=='WHOLESALE']
# Compute the mode of each column
modes = wholesale.mode()
# Convert the result to a new Excel file
modes.to_excel("modes.xlsx", index=False)
return "modes.xlsx"
def compute_mode_Large_supermarkets(file):
# Read the Excel file
df = pd.read_excel(file)
opm=df[df['Outlet Channel']=='Large supermarkets']
# Compute the mode of each column
modes = opm.mode()
# Convert the result to a new Excel file
modes.to_excel("modes.xlsx", index=False)
return "modes.xlsx"
def compute_mode_Small_Supermarkets(file):
# Read the Excel file
df = pd.read_excel(file)
opm=df[df['Outlet Channel']=='Small Supermarkets']
# Compute the mode of each column
modes = opm.mode()
# Convert the result to a new Excel file
modes.to_excel("modes.xlsx", index=False)
return "modes.xlsx"
def compute_mode_Neighbourhood_grocery(file):
# Read the Excel file
df = pd.read_excel(file)
opm=df[df['Outlet Channel']=='Neighbourhood grocery']
# Compute the mode of each column
modes = opm.mode()
# Convert the result to a new Excel file
modes.to_excel("modes.xlsx", index=False)
return "modes.xlsx"
# Create a Gradio interface
inputs = gr.File(label="Upload Excel File")
outputs = gr.File(label="Download Mode File")
iface1 = gr.Interface(fn=compute_mode_openmarket, inputs=inputs, outputs=outputs, title="Excel Mode Calculator")
# Create a Gradio interface
inputs = gr.File(label="Upload Excel File")
outputs = gr.File(label="Download Mode File")
iface2 = gr.Interface(fn=compute_mode_wholesale, inputs=inputs, outputs=outputs, title="Excel Mode Calculator")
# Create a Gradio interface
inputs = gr.File(label="Upload Excel File")
outputs = gr.File(label="Download Mode File")
iface3 = gr.Interface(fn=compute_mode_Small_Supermarkets, inputs=inputs, outputs=outputs, title="Excel Mode Calculator")
# Create a Gradio interface
inputs = gr.File(label="Upload Excel File")
outputs = gr.File(label="Download Mode File")
iface4 = gr.Interface(fn=compute_mode_Large_supermarkets, inputs=inputs, outputs=outputs, title="Excel Mode Calculator")
# Create a Gradio interface
inputs = gr.File(label="Upload Excel File")
outputs = gr.File(label="Download Mode File")
iface5 = gr.Interface(fn=compute_mode_Neighbourhood_grocery, inputs=inputs, outputs=outputs, title="Excel Mode Calculator")
# Launch the interface
gr.TabbedInterface([iface1,iface2,iface3,iface4,iface5],tab_names=['Open Market','Wholesale','Small Supermarkets','Large Supermarkets','Neighbourhood Grocery']).launch(share=True)