Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
import pickle
|
| 3 |
+
|
| 4 |
+
def load_and_display_data():
|
| 5 |
+
"""Loads the pickled data and formats it for display."""
|
| 6 |
+
try:
|
| 7 |
+
with open('canteen_surplus_data.pkl', 'rb') as f:
|
| 8 |
+
data = pickle.load(f)
|
| 9 |
+
# Format the dictionary for better display in Gradio
|
| 10 |
+
formatted_output = ""
|
| 11 |
+
for canteen_id, info in data.items():
|
| 12 |
+
formatted_output += f"Canteen ID: {canteen_id}\n"
|
| 13 |
+
formatted_output += f" Canteen Name: {info['canteen_name']}\n"
|
| 14 |
+
formatted_output += f" Predicted Surplus: {info['predicted_surplus']}\n"
|
| 15 |
+
formatted_output += f" NGO Requirement: {info['ngo_requirement']}\n"
|
| 16 |
+
formatted_output += "-" * 20 + "\n"
|
| 17 |
+
return formatted_output
|
| 18 |
+
except FileNotFoundError:
|
| 19 |
+
return "Error: canteen_surplus_data.pkl not found."
|
| 20 |
+
except Exception as e:
|
| 21 |
+
return f"An error occurred: {e}"
|
| 22 |
+
|
| 23 |
+
# Create a Gradio interface to display the data
|
| 24 |
+
iface = gr.Interface(
|
| 25 |
+
fn=load_and_display_data,
|
| 26 |
+
inputs=None, # No input needed to display the data
|
| 27 |
+
outputs="text",
|
| 28 |
+
title="Canteen Surplus and NGO Requirements",
|
| 29 |
+
description="Displays the predicted surplus units and NGO requirements for each canteen."
|
| 30 |
+
)
|
| 31 |
+
|
| 32 |
+
iface.launch()
|