Demo750 commited on
Commit
c4e0491
1 Parent(s): f09128e

Update Webpage.py

Browse files
Files changed (1) hide show
  1. Webpage.py +42 -31
Webpage.py CHANGED
@@ -104,40 +104,51 @@ def attention(notes, download1, download2, whole_display_prompt,
104
  ad_embeddings=ad_topic, ctpg_embeddings=ctpg_topic,
105
  surface_sizes=surfaces, Product_Group=prod_group,
106
  obj_detection_model_pth=None, num_topic=20, Gaze_Time_Type=gaze_type)
107
- return np.round(Gaze,2), Image.fromarray(np.flip(heatmap, axis=2))
108
 
109
  def greet(name, intensity):
110
  return "Hello " * intensity + name + "!"
111
 
112
- demo = gr.Interface(
113
- fn=attention,
114
- inputs=[gr.Markdown("""
115
- Instruction:
116
- 1. Click to upload or drag the entire image that contains BOTH ad and its context;
117
- 2. Draw bounding boxes in the order of: (each element can have more than 1 boxes; remember the number of boxes for each element you draw)
118
-    (a) Brand element(s) (skip if N.A.)
119
-    (b) Pictorial element(s), e.g. Objects, Person etc (skip if N.A.)
120
-    (c) Text element(s) (skip if N.A.)
121
-    (d) The advertisement.
122
-
123
- Two example ads are avialable for download: """),
124
- gr.DownloadButton(label="Download Example Magazine Ad Image", value='Demo/Magazine_Ad_Example.jpg'),
125
- gr.DownloadButton(label="Download Example Web Ad Image", value='Demo/Web_Ad_Example.jpg'),
126
- ImagePrompter(label="Upload Entire (Ad+Context) Image, and Draw Bounding Boxes", sources=['upload'], type="pil"),
127
- gr.Number(label="Number of brand bounding boxes drawn"),
128
- gr.Number(label="Number of pictorial bounding boxes drawn"),
129
- gr.Number(label="Number of text bounding boxes drawn"),
130
- gr.Dropdown(CATEGORIES, label="Product Category"),
131
- gr.Dropdown(LOCATIONS, label='Ad Location'),
132
- gr.Dropdown(GAZE_TYPE, label='Gaze Type')
133
- ],
134
- outputs=[gr.Number(label="Predicted Gaze (sec)"),
135
- gr.Image(label="Heatmap by ResNet50 (Hotter/Redder regions show more contribution)")],
136
- title="Ad Gaze Prediction",
137
- description="""This app accompanies: "Contextual Advertising with Theory-Informed Machine Learning", manuscript submitted to the Journal of Marketing.
138
- App Version: 1.0, Date: 10/24/2024.
139
- Warning: Due to computational efficiency, current version has not activated LLM generated ad topics. In future version, LLM topics will be activated in GPU environment.""",
140
- theme=gr.themes.Soft()
141
- )
 
 
 
 
 
 
 
 
 
 
 
142
 
143
  demo.launch(share=True)
 
104
  ad_embeddings=ad_topic, ctpg_embeddings=ctpg_topic,
105
  surface_sizes=surfaces, Product_Group=prod_group,
106
  obj_detection_model_pth=None, num_topic=20, Gaze_Time_Type=gaze_type)
107
+ return notes, notes, np.round(Gaze,2), notes, Image.fromarray(np.flip(heatmap, axis=2))
108
 
109
  def greet(name, intensity):
110
  return "Hello " * intensity + name + "!"
111
 
112
+ with gr.Blocks() as demo:
113
+ gr.Interface(
114
+ fn=attention,
115
+ inputs=[gr.Markdown("""
116
+ Instruction:
117
+ 1. Click to upload or drag the entire image that contains BOTH ad and its context;
118
+ 2. Draw bounding boxes in the order of: (each element can have more than 1 boxes; remember the number of boxes for each element you draw)
119
+    (a) Brand element(s) (skip if N.A.)
120
+    (b) Pictorial element(s), e.g. Objects, Person etc (skip if N.A.)
121
+    (c) Text element(s) (skip if N.A.)
122
+    (d) The advertisement.
123
+
124
+ Two example ads are avialable for download: """),
125
+ gr.DownloadButton(label="Download Example Image 1 of Ad and Context", value='Demo/Ad_Example1.jpg'),
126
+ gr.DownloadButton(label="Download Example Image 2 of Ad and Context", value='Demo/Ad_Example2.jpg'),
127
+ ImagePrompter(label="Upload Entire (Ad+Context) Image, and Draw Bounding Boxes", sources=['upload'], type="pil"),
128
+ gr.Number(label="Number of brand bounding boxes drawn"),
129
+ gr.Number(label="Number of pictorial bounding boxes drawn"),
130
+ gr.Number(label="Number of text bounding boxes drawn"),
131
+ gr.Dropdown(CATEGORIES, label="Product Category"),
132
+ gr.Dropdown(LOCATIONS, label='Ad Location'),
133
+ gr.Dropdown(GAZE_TYPE, label='Gaze Type')
134
+ ],
135
+ outputs=[gr.Markdown("""Note: Outputs could take around 70-80 seconds under current CPU environment (due to ResNet model)."""),
136
+ gr.Markdown("""### Predicted Gaze (sec) """),
137
+ gr.Number(show_label=False),
138
+ gr.Markdown("""### Heatmap by ResNet50 (Hotter/Redder regions show more contribution)"""),
139
+ gr.Image(show_label=False)],
140
+ title="Gazer 1.0: Ad Attention Prediction",
141
+ description="""This app accompanies: "Contextual Advertising with Theory-Informed Machine Learning", manuscript submitted to the Journal of Marketing.
142
+ App Version: 1.0, Date: 10/24/2024.
143
+ Note: Gazer 1.0 does not yet include LLM generated ad topics. Future updates will include this in a GPU environment.""",
144
+ theme=gr.themes.Soft()
145
+ )
146
+ gr.Markdown(
147
+ """
148
+ <div style='text-align: center; padding: 10px;'>
149
+ <p>Copyright © 2024 Manuscript Authors. All Rights Reserved.</p>
150
+ </div>
151
+ """
152
+ )
153
 
154
  demo.launch(share=True)