epochs-demos commited on
Commit
e670f01
·
1 Parent(s): 2d76394

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +43 -25
app.py CHANGED
@@ -50,6 +50,7 @@ with zipfile.ZipFile("artifacts/unimoda.zip", 'r') as zip_ref:
50
  zip_ref.extractall(RAW_PHOTOS_DIR)
51
 
52
 
 
53
  class TextEncoder:
54
  """Encodes the given text"""
55
 
@@ -121,37 +122,54 @@ def main(args):
121
  )
122
 
123
 
124
- def make_frontend(
125
- fn: Callable[[Image], str], flagging: bool = False, gantry: bool = False, app_name: str = "fashion-aggregator"
126
- ):
127
  """Creates a gradio.Interface frontend for text to image search function."""
128
 
129
- allow_flagging = "never"
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
130
 
131
- # HTML code to include the logo
132
- logo_html = f"<img src='path_to_your_logo' alt='Logo' style='width: 100px; height: 100px;' />"
133
-
134
  # Build a customized browser interface to a Python function
135
- layout = gr.Layout(
136
- gr.Row(
137
- [
138
- gr.Column([gr.outputs.HTML(logo_html), gr.Interface(
139
- fn=fn,
140
- outputs=gr.Gallery(label="Relevant Items", show_labels=True, label_position="below"),
141
- inputs=gr.inputs.Textbox(label="Item Description", placeholder="Enter item description here"),
142
- title="Fashion Aggregator",
143
- thumbnail=LOGO,
144
- description="Discover your perfect apparel effortlessly. Simply describe what you're looking for!",
145
- cache_examples=False,
146
- allow_flagging=allow_flagging,
147
- flagging_options=["incorrect", "offensive", "other"],
148
- )]),
149
- gr.Column([gr.outputs.HTML("This web app is for demonstration purposes only and not intended for commercial use.")])
150
- ]
151
- )
152
  )
153
 
154
- return layout
 
155
 
156
 
157
 
 
50
  zip_ref.extractall(RAW_PHOTOS_DIR)
51
 
52
 
53
+
54
  class TextEncoder:
55
  """Encodes the given text"""
56
 
 
122
  )
123
 
124
 
125
+ def make_frontend(fn: Callable[[str], List[str]], app_name: str = "fashion-aggregator"):
 
 
126
  """Creates a gradio.Interface frontend for text to image search function."""
127
 
128
+ def preprocess_input(input_str):
129
+ paths_and_scores = fn(input_str)
130
+ images = [gr.utils.image.load_image(path) for path in paths_and_scores]
131
+ return images
132
+
133
+ input_section = gr.inputs.Textbox(lines=2, placeholder="Enter item description here")
134
+
135
+ output_section = gr.Gallery(label="Relevant Items", show_labels=True, label_position="below")
136
+
137
+ # Define Interface layout with Gradio's Row and Column
138
+ interface_layout = gradio.ui.Row(
139
+ gradio.ui.Column(
140
+ gradio.ui.Textbox("Fashion Aggregator", label="Title"),
141
+ gradio.ui.Image(LOGO, label="Logo"),
142
+ gradio.ui.Textbox("Discover your perfect apparel effortlessly. Simply describe what you're looking for!", label="Description"),
143
+ ),
144
+ gradio.ui.Column(
145
+ gradio.ui.Section(
146
+ gradio.ui.Center(
147
+ input_section,
148
+ ),
149
+ gradio.ui.Center(
150
+ output_section,
151
+ ),
152
+ )
153
+ ),
154
+ gradio.ui.Column(
155
+ gradio.ui.Textbox("Disclaimer: The search results are based on embeddings and may not be always accurate.", label="Disclaimer"),
156
+ ),
157
+ )
158
 
 
 
 
159
  # Build a customized browser interface to a Python function
160
+ frontend = gr.Interface(
161
+ fn=preprocess_input,
162
+ inputs=input_section,
163
+ outputs=output_section,
164
+ layout=interface_layout,
165
+ allow_flagging=False,
166
+ title=app_name,
167
+ thumbnail=LOGO,
168
+ description="Enter the description of the item you're looking for and see the corresponding images!",
 
 
 
 
 
 
 
 
169
  )
170
 
171
+ return frontend
172
+
173
 
174
 
175