Commit
Β·
fca4028
1
Parent(s):
5ff38a4
chore: Add samples for a quick app run
Browse files- .gitignore +2 -0
- app.py +30 -7
- predictor.py β app_predictor.py +0 -0
- assets/sample.jpeg +3 -0
.gitignore
CHANGED
|
@@ -3,6 +3,8 @@ __pycache__/
|
|
| 3 |
*.py[codz]
|
| 4 |
*$py.class
|
| 5 |
|
|
|
|
|
|
|
| 6 |
# C extensions
|
| 7 |
*.so
|
| 8 |
|
|
|
|
| 3 |
*.py[codz]
|
| 4 |
*$py.class
|
| 5 |
|
| 6 |
+
*.csv
|
| 7 |
+
|
| 8 |
# C extensions
|
| 9 |
*.so
|
| 10 |
|
app.py
CHANGED
|
@@ -1,6 +1,6 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
|
| 3 |
-
from
|
| 4 |
|
| 5 |
# π CUSTOM CSS
|
| 6 |
css_code = """
|
|
@@ -56,7 +56,7 @@ with gr.Blocks(
|
|
| 56 |
gr.Markdown("## π Classification Inputs")
|
| 57 |
|
| 58 |
mode_radio = gr.Radio(
|
| 59 |
-
choices=["Multimodal", "
|
| 60 |
value="Multimodal",
|
| 61 |
label="Choose Classification Mode:",
|
| 62 |
)
|
|
@@ -64,14 +64,14 @@ with gr.Blocks(
|
|
| 64 |
text_input = gr.Textbox(
|
| 65 |
label="Product Description:",
|
| 66 |
placeholder="e.g., Apple iPhone 15 Pro Max 256GB",
|
| 67 |
-
lines=
|
| 68 |
)
|
| 69 |
|
| 70 |
image_input = gr.Image(
|
| 71 |
label="Product Image",
|
| 72 |
type="filepath",
|
| 73 |
visible=True,
|
| 74 |
-
height=
|
| 75 |
width="100%",
|
| 76 |
)
|
| 77 |
|
|
@@ -88,9 +88,9 @@ with gr.Blocks(
|
|
| 88 |
"""**π‘ How to use this app**
|
| 89 |
|
| 90 |
This app classifies a product based on its description and image.
|
| 91 |
-
- **Multimodal:**
|
| 92 |
-
- **
|
| 93 |
-
- **
|
| 94 |
"""
|
| 95 |
)
|
| 96 |
|
|
@@ -100,6 +100,28 @@ with gr.Blocks(
|
|
| 100 |
label="Predict category", num_top_classes=5
|
| 101 |
)
|
| 102 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 103 |
# π ABOUT TAB
|
| 104 |
with gr.TabItem("βΉοΈ About"):
|
| 105 |
gr.Markdown("""
|
|
@@ -137,6 +159,7 @@ The final classification is performed by a Multi-layer Perceptron (MLP) trained
|
|
| 137 |
## Performance Summary
|
| 138 |
|
| 139 |
The following table summarizes the performance of all models trained in this project.
|
|
|
|
| 140 |
<br>
|
| 141 |
|
| 142 |
| Model | Modality | Accuracy | Macro Avg F1-Score | Weighted Avg F1-Score |
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
|
| 3 |
+
from app_predictor import predict
|
| 4 |
|
| 5 |
# π CUSTOM CSS
|
| 6 |
css_code = """
|
|
|
|
| 56 |
gr.Markdown("## π Classification Inputs")
|
| 57 |
|
| 58 |
mode_radio = gr.Radio(
|
| 59 |
+
choices=["Multimodal", "Image Only", "Text Only"],
|
| 60 |
value="Multimodal",
|
| 61 |
label="Choose Classification Mode:",
|
| 62 |
)
|
|
|
|
| 64 |
text_input = gr.Textbox(
|
| 65 |
label="Product Description:",
|
| 66 |
placeholder="e.g., Apple iPhone 15 Pro Max 256GB",
|
| 67 |
+
lines=1,
|
| 68 |
)
|
| 69 |
|
| 70 |
image_input = gr.Image(
|
| 71 |
label="Product Image",
|
| 72 |
type="filepath",
|
| 73 |
visible=True,
|
| 74 |
+
height=300,
|
| 75 |
width="100%",
|
| 76 |
)
|
| 77 |
|
|
|
|
| 88 |
"""**π‘ How to use this app**
|
| 89 |
|
| 90 |
This app classifies a product based on its description and image.
|
| 91 |
+
- **Multimodal:** The most accurate mode, using both the image and a detailed description for prediction.
|
| 92 |
+
- **Image Only:** Highly effective for visual products, relying solely on the product image.
|
| 93 |
+
- **Text Only:** Less precise, this mode requires a very descriptive and specific product description to achieve good results.
|
| 94 |
"""
|
| 95 |
)
|
| 96 |
|
|
|
|
| 100 |
label="Predict category", num_top_classes=5
|
| 101 |
)
|
| 102 |
|
| 103 |
+
# π EXAMPLES SECTION
|
| 104 |
+
gr.Examples(
|
| 105 |
+
examples=[
|
| 106 |
+
[
|
| 107 |
+
"Multimodal",
|
| 108 |
+
"Red Electric Guitar β Stratocaster Style, 6-String, White Pickguard, Solid-Body, Ideal for Rock & Roll",
|
| 109 |
+
"./assets/sample.jpeg",
|
| 110 |
+
],
|
| 111 |
+
["Image Only", None, "./assets/sample.jpeg"],
|
| 112 |
+
[
|
| 113 |
+
"Text Only",
|
| 114 |
+
"Red Electric Guitar β Stratocaster Style, 6-String, White Pickguard, Solid-Body, Ideal for Rock & Roll",
|
| 115 |
+
None,
|
| 116 |
+
],
|
| 117 |
+
],
|
| 118 |
+
label="Select an example to pre-fill the inputs, then click the 'Classify Product' button.",
|
| 119 |
+
inputs=[mode_radio, text_input, image_input],
|
| 120 |
+
# outputs=output_label,
|
| 121 |
+
# fn=predict,
|
| 122 |
+
# cache_examples=True,
|
| 123 |
+
)
|
| 124 |
+
|
| 125 |
# π ABOUT TAB
|
| 126 |
with gr.TabItem("βΉοΈ About"):
|
| 127 |
gr.Markdown("""
|
|
|
|
| 159 |
## Performance Summary
|
| 160 |
|
| 161 |
The following table summarizes the performance of all models trained in this project.
|
| 162 |
+
|
| 163 |
<br>
|
| 164 |
|
| 165 |
| Model | Modality | Accuracy | Macro Avg F1-Score | Weighted Avg F1-Score |
|
predictor.py β app_predictor.py
RENAMED
|
File without changes
|
assets/sample.jpeg
ADDED
|
Git LFS Details
|