iBrokeTheCode commited on
Commit
f02a5fd
·
1 Parent(s): dd8438e

chore: Complete User Interface

Browse files
Files changed (2) hide show
  1. app.py +33 -5
  2. base.py +0 -155
app.py CHANGED
@@ -1,5 +1,23 @@
1
  import gradio as gr
2
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
3
 
4
  # 📌 FUNCTIONS
5
  def predict(mode, text, image_path):
@@ -54,16 +72,23 @@ def update_inputs(mode: str):
54
  with gr.Blocks(
55
  title="Multimodal Product Classification",
56
  theme=gr.themes.Ocean(),
 
57
  ) as demo:
58
  with gr.Tabs():
59
  # 📌 APP TAB
60
  with gr.TabItem("App"):
61
- gr.Markdown("# 🛍️ Multimodal Product Classification")
 
 
 
 
 
62
 
63
  with gr.Row(equal_height=True):
 
64
  with gr.Column():
65
  with gr.Column():
66
- gr.Markdown("## ⚙️ Classification Inputs")
67
 
68
  mode_radio = gr.Radio(
69
  choices=["Multimodal", "Text Only", "Image Only"],
@@ -80,7 +105,7 @@ with gr.Blocks(
80
  label="Product Image",
81
  type="filepath",
82
  visible=True,
83
- height=300,
84
  width="100%",
85
  )
86
 
@@ -88,6 +113,7 @@ with gr.Blocks(
88
  "✨ Classify Product", variant="primary"
89
  )
90
 
 
91
  with gr.Column():
92
  with gr.Column():
93
  gr.Markdown("## 📊 Results")
@@ -102,6 +128,8 @@ with gr.Blocks(
102
  """
103
  )
104
 
 
 
105
  output_label = gr.Label(
106
  label="Predict category", num_top_classes=5
107
  )
@@ -143,8 +171,8 @@ This evolution demonstrates the ability to design a scalable microservices syste
143
  """)
144
 
145
  # 📌 FOOTER
146
- gr.HTML("<hr>")
147
- with gr.Row():
148
  gr.Markdown("""
149
  <div style="text-align: center; margin-bottom: 1.5rem;">
150
  <b>Connect with me:</b> 💼 <a href="https://www.linkedin.com/in/alex-turpo/" target="_blank">LinkedIn</a> •
 
1
  import gradio as gr
2
 
3
+ # 📌 CUSTOM CSS
4
+ css_code = """
5
+ #footer-container {
6
+ position: fixed;
7
+ bottom: 0;
8
+ left: 0;
9
+ right: 0;
10
+ z-index: 1000;
11
+ background-color: var(--background-fill-primary);
12
+ padding: var(--spacing-md);
13
+ border-top: 1px solid var(--border-color-primary);
14
+ }
15
+
16
+ .gradio-container {
17
+ padding-bottom: 70px !important;
18
+ }
19
+ """
20
+
21
 
22
  # 📌 FUNCTIONS
23
  def predict(mode, text, image_path):
 
72
  with gr.Blocks(
73
  title="Multimodal Product Classification",
74
  theme=gr.themes.Ocean(),
75
+ css=css_code,
76
  ) as demo:
77
  with gr.Tabs():
78
  # 📌 APP TAB
79
  with gr.TabItem("App"):
80
+ gr.Markdown("""
81
+ <div style="text-align: center;">
82
+ <h1>🛍️ Multimodal Product Classification</h1>
83
+ </div>
84
+ <br><br>
85
+ """)
86
 
87
  with gr.Row(equal_height=True):
88
+ # 📌 CLASSIFICATION INPUTS COLUMN
89
  with gr.Column():
90
  with gr.Column():
91
+ gr.Markdown("## 📝 Classification Inputs")
92
 
93
  mode_radio = gr.Radio(
94
  choices=["Multimodal", "Text Only", "Image Only"],
 
105
  label="Product Image",
106
  type="filepath",
107
  visible=True,
108
+ height=350,
109
  width="100%",
110
  )
111
 
 
113
  "✨ Classify Product", variant="primary"
114
  )
115
 
116
+ # 📌 RESULTS COLUMN
117
  with gr.Column():
118
  with gr.Column():
119
  gr.Markdown("## 📊 Results")
 
128
  """
129
  )
130
 
131
+ gr.HTML("<hr>")
132
+
133
  output_label = gr.Label(
134
  label="Predict category", num_top_classes=5
135
  )
 
171
  """)
172
 
173
  # 📌 FOOTER
174
+ # gr.HTML("<hr>")
175
+ with gr.Row(elem_id="footer-container"):
176
  gr.Markdown("""
177
  <div style="text-align: center; margin-bottom: 1.5rem;">
178
  <b>Connect with me:</b> 💼 <a href="https://www.linkedin.com/in/alex-turpo/" target="_blank">LinkedIn</a> •
base.py DELETED
@@ -1,155 +0,0 @@
1
- import gradio as gr
2
-
3
-
4
- # 📌 FUNCTIONS
5
- def predict(mode, text, image_path):
6
- # ... your existing predict function ...
7
- multimodal_output = {
8
- "abcat0100000": 0.05,
9
- "abcat0200000": 0.10,
10
- "abcat0300000": 0.20,
11
- "abcat0400000": 0.45,
12
- "abcat0500000": 0.20,
13
- }
14
- text_only_output = {
15
- "abcat0100000": 0.08,
16
- "abcat0200000": 0.15,
17
- "abcat0300000": 0.25,
18
- "abcat0400000": 0.35,
19
- "abcat0500000": 0.17,
20
- }
21
- image_only_output = {
22
- "abcat0100000": 0.10,
23
- "abcat0200000": 0.20,
24
- "abcat0300000": 0.30,
25
- "abcat0400000": 0.25,
26
- "abcat0500000": 0.15,
27
- }
28
-
29
- if mode == "Multimodal":
30
- return multimodal_output
31
- elif mode == "Text Only":
32
- return text_only_output
33
- elif mode == "Image Only":
34
- return image_only_output
35
- else:
36
- return {}
37
-
38
-
39
- def update_inputs(mode: str):
40
- # ... your existing update_inputs function ...
41
- if mode == "Multimodal":
42
- return gr.Textbox(visible=True), gr.Image(visible=True)
43
- elif mode == "Text Only":
44
- return gr.Textbox(visible=True), gr.Image(visible=False)
45
- elif mode == "Image Only":
46
- return gr.Textbox(visible=False), gr.Image(visible=True)
47
- else:
48
- return gr.Textbox(visible=True), gr.Image(visible=True)
49
-
50
-
51
- # 📌 CUSTOM CSS FOR FIXED FOOTER
52
- css_code = """
53
- /* Target the footer container by its ID and apply fixed positioning */
54
- #footer-container {
55
- position: fixed;
56
- bottom: 0;
57
- left: 0;
58
- right: 0;
59
- z-index: 1000; /* Ensure it stays on top of other content */
60
- background-color: var(--background-fill-primary); /* Use a Gradio theme variable */
61
- padding: var(--spacing-md);
62
- border-top: 1px solid var(--border-color-primary);
63
- }
64
-
65
- /* Add padding to the body to prevent content from being hidden by the footer */
66
- .gradio-container {
67
- padding-bottom: 70px !important;
68
- }
69
- """
70
-
71
- # 📌 USER INTERFACE
72
- with gr.Blocks(
73
- title="Multimodal Product Classification",
74
- theme=gr.themes.Ocean(),
75
- css=css_code,
76
- ) as demo:
77
- # 📌 TABS
78
- with gr.Tabs():
79
- # ... your existing tabs ...
80
- # 📌 APP TAB
81
- with gr.TabItem("App"):
82
- gr.Markdown("# 🛍️ Multimodal Product Classification")
83
-
84
- with gr.Row(equal_height=True):
85
- with gr.Column(scale=1):
86
- with gr.Column():
87
- gr.Markdown("## ⚙️ Classification Inputs")
88
-
89
- mode_radio = gr.Radio(
90
- choices=["Multimodal", "Text Only", "Image Only"],
91
- value="Multimodal",
92
- label="Choose Classification Mode:",
93
- )
94
-
95
- text_input = gr.Textbox(
96
- label="Product Description:",
97
- placeholder="e.g., Apple iPhone 15 Pro Max 256GB",
98
- )
99
-
100
- image_input = gr.Image(
101
- label="Product Image", type="filepath", visible=True
102
- )
103
-
104
- classify_button = gr.Button(
105
- "✨ Classify Product", variant="primary"
106
- )
107
-
108
- with gr.Column(scale=2):
109
- with gr.Column():
110
- gr.Markdown("## 📊 Results")
111
-
112
- gr.Markdown(
113
- """**💡 How to use this app**
114
-
115
- This app classifies a product based on its description and image.
116
- - **Multimodal:** Uses both text and image for the most accurate prediction.
117
- - **Text Only:** Uses only the product description.
118
- - **Image Only:** Uses only the product image.
119
- """
120
- )
121
-
122
- output_label = gr.Label(
123
- label="Predict category", num_top_classes=5
124
- )
125
-
126
- # 📌 ABOUT TAB
127
- with gr.TabItem("About"):
128
- gr.Markdown("""...""")
129
-
130
- # 📌 MODEL TAB
131
- with gr.TabItem("Model"):
132
- gr.Markdown("""...""")
133
-
134
- # 📌 FOOTER
135
- with gr.Row(elem_id="footer-container"):
136
- gr.HTML("""
137
- <div style="text-align: center;">
138
- <b>Connect with me:</b> 💼 <a href="https://www.linkedin.com/in/alex-turpo/" target="_blank">LinkedIn</a> •
139
- 🐱 <a href="https://github.com/iBrokeTheCode" target="_blank">GitHub</a> •
140
- 🤗 <a href="https://huggingface.co/iBrokeTheCode" target="_blank">Hugging Face</a>
141
- </div>
142
- """)
143
-
144
- # 📌 EVENT LISTENERS
145
- mode_radio.change(
146
- fn=update_inputs,
147
- inputs=mode_radio,
148
- outputs=[text_input, image_input],
149
- )
150
-
151
- classify_button.click(
152
- fn=predict, inputs=[mode_radio, text_input, image_input], outputs=output_label
153
- )
154
-
155
- demo.launch()