Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,46 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from transformers import pipeline
|
| 2 |
+
import gradio as gr
|
| 3 |
+
|
| 4 |
+
# Initialize the pipeline
|
| 5 |
+
pipe = pipeline("text-classification", model="himanshutitoria/quick-commerce-perishability-model")
|
| 6 |
+
|
| 7 |
+
# Prediction function
|
| 8 |
+
def predict(text):
|
| 9 |
+
result = pipe(text)
|
| 10 |
+
return result[0]["label"]
|
| 11 |
+
|
| 12 |
+
# Define the interface
|
| 13 |
+
with gr.Blocks() as iface:
|
| 14 |
+
# Add an image at the top
|
| 15 |
+
gr.Image(
|
| 16 |
+
value="top_image.webp", # Replace with your image URL or file path
|
| 17 |
+
label="Perishability Tagging",
|
| 18 |
+
show_label=False,
|
| 19 |
+
)
|
| 20 |
+
|
| 21 |
+
input_textbox = gr.Textbox(
|
| 22 |
+
label="Enter a Product Name",
|
| 23 |
+
placeholder="Enter a name here...",
|
| 24 |
+
interactive=True,
|
| 25 |
+
)
|
| 26 |
+
|
| 27 |
+
# Add the main Gradio interface
|
| 28 |
+
with gr.Row():
|
| 29 |
+
gr.Markdown("# Quick Commerce Perishability Tagging - Zepto")
|
| 30 |
+
|
| 31 |
+
outputs = gr.Textbox(label="Predicted result")
|
| 32 |
+
gr.Interface(
|
| 33 |
+
fn=predict,
|
| 34 |
+
inputs=input_textbox,
|
| 35 |
+
outputs=outputs,
|
| 36 |
+
examples=[
|
| 37 |
+
["Milk"],
|
| 38 |
+
["Perfume"],
|
| 39 |
+
["Refined oil"],
|
| 40 |
+
["Tata Salt"],
|
| 41 |
+
["Cheese"],
|
| 42 |
+
["Butterscotch Icecream"],
|
| 43 |
+
["Thepla"],
|
| 44 |
+
],
|
| 45 |
+
)
|
| 46 |
+
iface.launch()
|