epochs-demos commited on
Commit
12c88cf
·
1 Parent(s): 2c792b1

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +132 -126
app.py CHANGED
@@ -112,99 +112,99 @@ class Retriever:
112
  return paths_and_scores
113
 
114
 
115
- def main(args):
116
- predictor = PredictorBackend(url=args.model_url)
117
 
118
- # Read the image file and encode it as base64
119
- with open("./1001epochs.png", "rb") as f:
120
- image_data = f.read()
121
- image_base64 = base64.b64encode(image_data).decode("utf-8")
122
-
123
- allow_flagging = "never"
124
-
125
- title = f"""
126
- <h1 style="background-image: linear-gradient(to right, #ADD8E6, #87CEFA); -webkit-background-clip: text;
127
- -webkit-text-fill-color: transparent; text-align: center;">
128
- Fashion Aggregator
129
- </h1>
130
- """
131
 
132
- description = f"""
133
- <div style="display: flex; align-items: center; justify-content: center; flex-direction: column;">
134
- <img src='data:image/jpeg;base64,{image_base64}' width='50' height='50' style="margin-right: 10px;"/>
135
- <p style="font-size: small; color: gray; margin-top: 10px;">
136
- Disclaimer: This web app is for demonstration purposes only and not intended for commercial use. Contact: [email protected] for full solution.
137
- </p>
138
- <p style="font-size: 18px; color: blue; margin-top: 10px; text-align: center;">
139
- Discover your perfect apparel effortlessly. Simply describe what you're looking for!
140
- </p>
141
- </div>
142
- """
143
-
144
- frontend = gr.Interface(
145
- fn=predictor.run,
146
- inputs=gr.inputs.Textbox(label="Item Description", placeholder="Enter item description here"),
147
- outputs=gr.Gallery(label="Relevant Items", show_labels=True, label_position="below"),
148
- title=title,
149
- description=description,
150
- cache_examples=False, # should we cache those inputs for faster inference? slows down start
151
- allow_flagging=allow_flagging, # should we show users the option to "flag" outputs?
152
- flagging_options=["incorrect", "offensive", "other"], # what options do users have for feedback?
153
- )
154
- frontend.launch(
155
- # server_name="0.0.0.0", # make server accessible, binding all interfaces # noqa: S104
156
- # server_port=args.port, # set a port to bind to, failing if unavailable
157
- # share=False, # should we create a (temporary) public link on https://gradio.app?
158
- )
159
-
160
-
161
- def make_frontend(
162
- fn: Callable[[Image], str], flagging: bool = False, gantry: bool = False, app_name: str = "fashion-aggregator"
163
- ):
164
- """Creates a gradio.Interface frontend for text to image search function."""
165
-
166
- allow_flagging = "never"
167
-
168
- title = f"""
169
- <h1 style="background-image: linear-gradient(to right, #ADD8E6, #87CEFA); -webkit-background-clip: text;
170
- -webkit-text-fill-color: transparent; text-align: center;">
171
- Fashion Aggregator
172
- </h1>
173
- """
174
 
175
- disclaimer = f"""
176
- <div style="display: flex; align-items: center; justify-content: center;">
177
- <img src='data:image/jpeg;base64,{image_base64}' width='50' height='50' style="margin-right: 10px;"/>
178
- <p style="font-size: small; color: gray;">
179
- Disclaimer: This web app is for demonstration purposes only and not intended for commercial use. Contact: [email protected] for full solution.
180
- </p>
181
- </div>
182
- """
183
 
184
- description = f"""
185
- <div style="display: flex; align-items: center; justify-content: center; flex-direction: column;">
186
- <img src='data:image/jpeg;base64,{image_base64}' width='50' height='50' style="margin-right: 10px;"/>
187
- <p style="font-size: small; color: gray; margin-top: 10px;">
188
- Disclaimer: The search results are based on embeddings and may not always be accurate.
189
- </p>
190
- <p style="font-size: 18px; color: blue; margin-top: 10px; text-align: center;">
191
- Discover your perfect apparel effortlessly. Simply describe what you're looking for!
192
- </p>
193
- </div>
194
- """
195
-
196
- frontend = gr.Interface(
197
- fn=fn,
198
- inputs=gr.inputs.Textbox(label="Item Description", placeholder="Enter item description here"),
199
- outputs=gr.Gallery(label="Relevant Items", show_labels=True, label_position="below"),
200
- title=title,
201
- description=description,
202
- cache_examples=False, # should we cache those inputs for faster inference? slows down start
203
- allow_flagging=allow_flagging, # should we show users the option to "flag" outputs?
204
- flagging_options=["incorrect", "offensive", "other"], # what options do users have for feedback?
205
- )
206
-
207
- return frontend
208
 
209
 
210
  class PredictorBackend:
@@ -240,40 +240,46 @@ class PredictorBackend:
240
  logging.info(f"PRED >begin\n{pred}\nPRED >end")
241
 
242
 
243
- def _make_parser():
244
- parser = argparse.ArgumentParser(description=__doc__)
245
- parser.add_argument(
246
- "--model_url",
247
- default=None,
248
- type=str,
249
- help="Identifies a URL to which to send image data. Data is base64-encoded, converted to a utf-8 string, and then set via a POST request as JSON with the key 'image'. Default is None, which instead sends the data to a model running locally.",
250
- )
251
- parser.add_argument(
252
- "--port",
253
- default=DEFAULT_PORT,
254
- type=int,
255
- help=f"Port on which to expose this server. Default is {DEFAULT_PORT}.",
256
- )
257
- parser.add_argument(
258
- "--flagging",
259
- action="store_true",
260
- help="Pass this flag to allow users to 'flag' model behavior and provide feedback.",
261
- )
262
- parser.add_argument(
263
- "--gantry",
264
- action="store_true",
265
- help="Pass --flagging and this flag to log user feedback to Gantry. Requires GANTRY_API_KEY to be defined as an environment variable.",
266
- )
267
- parser.add_argument(
268
- "--application",
269
- default=DEFAULT_APPLICATION_NAME,
270
- type=str,
271
- help=f"Name of the Gantry application to which feedback should be logged, if --gantry and --flagging are passed. Default is {DEFAULT_APPLICATION_NAME}.",
272
- )
273
- return parser
274
-
275
-
276
- if __name__ == "__main__":
277
- parser = _make_parser()
278
- args = parser.parse_args()
279
- main(args)
 
 
 
 
 
 
 
112
  return paths_and_scores
113
 
114
 
115
+ # def main(args):
116
+ # predictor = PredictorBackend(url=args.model_url)
117
 
118
+ # # Read the image file and encode it as base64
119
+ # with open("./1001epochs.png", "rb") as f:
120
+ # image_data = f.read()
121
+ # image_base64 = base64.b64encode(image_data).decode("utf-8")
122
+
123
+ # allow_flagging = "never"
124
+
125
+ # title = f"""
126
+ # <h1 style="background-image: linear-gradient(to right, #ADD8E6, #87CEFA); -webkit-background-clip: text;
127
+ # -webkit-text-fill-color: transparent; text-align: center;">
128
+ # Fashion Aggregator
129
+ # </h1>
130
+ # """
131
 
132
+ # description = f"""
133
+ # <div style="display: flex; align-items: center; justify-content: center; flex-direction: column;">
134
+ # <img src='data:image/jpeg;base64,{image_base64}' width='50' height='50' style="margin-right: 10px;"/>
135
+ # <p style="font-size: small; color: gray; margin-top: 10px;">
136
+ # Disclaimer: This web app is for demonstration purposes only and not intended for commercial use. Contact: [email protected] for full solution.
137
+ # </p>
138
+ # <p style="font-size: 18px; color: blue; margin-top: 10px; text-align: center;">
139
+ # Discover your perfect apparel effortlessly. Simply describe what you're looking for!
140
+ # </p>
141
+ # </div>
142
+ # """
143
+
144
+ # frontend = gr.Interface(
145
+ # fn=predictor.run,
146
+ # inputs=gr.inputs.Textbox(label="Item Description", placeholder="Enter item description here"),
147
+ # outputs=gr.Gallery(label="Relevant Items", show_labels=True, label_position="below"),
148
+ # title=title,
149
+ # description=description,
150
+ # cache_examples=False, # should we cache those inputs for faster inference? slows down start
151
+ # allow_flagging=allow_flagging, # should we show users the option to "flag" outputs?
152
+ # flagging_options=["incorrect", "offensive", "other"], # what options do users have for feedback?
153
+ # )
154
+ # frontend.launch(
155
+ # # server_name="0.0.0.0", # make server accessible, binding all interfaces # noqa: S104
156
+ # # server_port=args.port, # set a port to bind to, failing if unavailable
157
+ # # share=False, # should we create a (temporary) public link on https://gradio.app?
158
+ # )
159
+
160
+
161
+ # def make_frontend(
162
+ # fn: Callable[[Image], str], flagging: bool = False, gantry: bool = False, app_name: str = "fashion-aggregator"
163
+ # ):
164
+ # """Creates a gradio.Interface frontend for text to image search function."""
165
+
166
+ # allow_flagging = "never"
167
+
168
+ # title = f"""
169
+ # <h1 style="background-image: linear-gradient(to right, #ADD8E6, #87CEFA); -webkit-background-clip: text;
170
+ # -webkit-text-fill-color: transparent; text-align: center;">
171
+ # Fashion Aggregator
172
+ # </h1>
173
+ # """
174
 
175
+ # disclaimer = f"""
176
+ # <div style="display: flex; align-items: center; justify-content: center;">
177
+ # <img src='data:image/jpeg;base64,{image_base64}' width='50' height='50' style="margin-right: 10px;"/>
178
+ # <p style="font-size: small; color: gray;">
179
+ # Disclaimer: This web app is for demonstration purposes only and not intended for commercial use. Contact: [email protected] for full solution.
180
+ # </p>
181
+ # </div>
182
+ # """
183
 
184
+ # description = f"""
185
+ # <div style="display: flex; align-items: center; justify-content: center; flex-direction: column;">
186
+ # <img src='data:image/jpeg;base64,{image_base64}' width='50' height='50' style="margin-right: 10px;"/>
187
+ # <p style="font-size: small; color: gray; margin-top: 10px;">
188
+ # Disclaimer: The search results are based on embeddings and may not always be accurate.
189
+ # </p>
190
+ # <p style="font-size: 18px; color: blue; margin-top: 10px; text-align: center;">
191
+ # Discover your perfect apparel effortlessly. Simply describe what you're looking for!
192
+ # </p>
193
+ # </div>
194
+ # """
195
+
196
+ # frontend = gr.Interface(
197
+ # fn=fn,
198
+ # inputs=gr.inputs.Textbox(label="Item Description", placeholder="Enter item description here"),
199
+ # outputs=gr.Gallery(label="Relevant Items", show_labels=True, label_position="below"),
200
+ # title=title,
201
+ # description=description,
202
+ # cache_examples=False, # should we cache those inputs for faster inference? slows down start
203
+ # allow_flagging=allow_flagging, # should we show users the option to "flag" outputs?
204
+ # flagging_options=["incorrect", "offensive", "other"], # what options do users have for feedback?
205
+ # )
206
+
207
+ # return frontend
208
 
209
 
210
  class PredictorBackend:
 
240
  logging.info(f"PRED >begin\n{pred}\nPRED >end")
241
 
242
 
243
+ predictor = PredictorBackend()
244
+
245
+ # Read the image file and encode it as base64
246
+ with open("./1001epochs.png", "rb") as f:
247
+ image_data = f.read()
248
+ image_base64 = base64.b64encode(image_data).decode("utf-8")
249
+
250
+ allow_flagging = "never"
251
+
252
+ title = f"""
253
+ <h1 style="background-image: linear-gradient(to right, #ADD8E6, #87CEFA); -webkit-background-clip: text;
254
+ -webkit-text-fill-color: transparent; text-align: center;">
255
+ Fashion Aggregator
256
+ </h1>
257
+ """
258
+
259
+ description = f"""
260
+ <div style="display: flex; align-items: center; justify-content: center; flex-direction: column;">
261
+ <img src='data:image/jpeg;base64,{image_base64}' width='50' height='50' style="margin-right: 10px;"/>
262
+ <p style="font-size: small; color: gray; margin-top: 10px;">
263
+ Disclaimer: This web app is for demonstration purposes only and not intended for commercial use. Contact: [email protected] for full solution.
264
+ </p>
265
+ <p style="font-size: 18px; color: blue; margin-top: 10px; text-align: center;">
266
+ Discover your perfect apparel effortlessly. Simply describe what you're looking for!
267
+ </p>
268
+ </div>
269
+ """
270
+
271
+ frontend = gr.Interface(
272
+ fn=predictor.run,
273
+ inputs=gr.inputs.Textbox(label="Item Description", placeholder="Enter item description here"),
274
+ outputs=gr.Gallery(label="Relevant Items", show_labels=True, label_position="below"),
275
+ title=title,
276
+ description=description,
277
+ cache_examples=False, # should we cache those inputs for faster inference? slows down start
278
+ allow_flagging=allow_flagging, # should we show users the option to "flag" outputs?
279
+ flagging_options=["incorrect", "offensive", "other"], # what options do users have for feedback?
280
+ )
281
+ frontend.launch(
282
+ # server_name="0.0.0.0", # make server accessible, binding all interfaces # noqa: S104
283
+ # server_port=args.port, # set a port to bind to, failing if unavailable
284
+ # share=False, # should we create a (temporary) public link on https://gradio.app?
285
+ )