clarice7 commited on
Commit
a7709a7
1 Parent(s): 46a4b10

Upload 2 files

Browse files
Files changed (2) hide show
  1. app.py +17 -17
  2. requirements.txt +2 -1
app.py CHANGED
@@ -11,6 +11,9 @@ from openai import OpenAI
11
  import gradio as gr
12
  import huggingface_hub
13
  from datasets import load_dataset
 
 
 
14
 
15
  api_key = os.environ.get("API_TOKEN")
16
  headers = {
@@ -112,30 +115,27 @@ def simulate(image0, image1):
112
  avg_preference = sum(preferences) / len(preferences)
113
  avg_prob = sum(probs) / len(preferences)
114
 
115
- return avg_preference
116
-
117
- subtitle = "Upload two images of emails and see which is generally preferred by Petco customers!"
118
-
119
-
120
- from pathlib import Path
121
 
122
- def upload_file(filepath):
123
- name = Path(filepath).name
124
- return [gr.UploadButton(visible=False), gr.DownloadButton(label=f"{name}", value=filepath, visible=True)]
 
125
 
126
- # with gr.Blocks() as demo:
127
- # gr.Markdown("First upload a file and and then you'll be able download it (but only once!)")
128
- # with gr.Row():
129
- # u = gr.UploadButton("Upload a file", file_count="single")
130
- # d = gr.DownloadButton("Download the file", visible=False)
131
 
132
- # u.upload(upload_file, u, [u, d])
133
- # d.click(download_file, None, [u, d])
134
 
135
  demo = gr.Interface(fn=simulate,
136
  inputs=[gr.UploadButton("Click to Upload Email 0", file_types=["image"], file_count="single"),
137
  gr.UploadButton("Click to Upload Email 1", file_types=["image"], file_count="single")],
138
- outputs="text",
 
139
  title="Pairwise Simulation of Petco Email Preference",
140
  description=subtitle
141
  )
 
11
  import gradio as gr
12
  import huggingface_hub
13
  from datasets import load_dataset
14
+ from wordcloud import WordCloud
15
+ import matplotlib.pyplot as plt
16
+ import ast
17
 
18
  api_key = os.environ.get("API_TOKEN")
19
  headers = {
 
115
  avg_preference = sum(preferences) / len(preferences)
116
  avg_prob = sum(probs) / len(preferences)
117
 
118
+ preference = 0 if avg_preference < 0.5 else 1
119
+
120
+ right_reasons = [reasons[i] for i in len(reasons) if preferences[i] == preference]
121
+ reasons_list = ast.literal_eval(right_reasons)
122
+ all_reasons = ','.join(reasons_list)
123
+ wordcloud = WordCloud(width = 800, height = 400, background_color ='white').generate(all_reasons)
124
 
125
+ plt.figure(figsize=(10,5))
126
+ plt.imshow(wordcloud, interpolation='bilinear')
127
+ plt.axis("off")
128
+ plt.show()
129
 
130
+ return preference, plt
 
 
 
 
131
 
132
+ subtitle = "Upload two images of emails and see which is generally preferred by Petco customers!"
 
133
 
134
  demo = gr.Interface(fn=simulate,
135
  inputs=[gr.UploadButton("Click to Upload Email 0", file_types=["image"], file_count="single"),
136
  gr.UploadButton("Click to Upload Email 1", file_types=["image"], file_count="single")],
137
+ outputs=["text",
138
+ gr.Plot(value=plt)],
139
  title="Pairwise Simulation of Petco Email Preference",
140
  description=subtitle
141
  )
requirements.txt CHANGED
@@ -2,4 +2,5 @@ openai
2
  https://gradio-builds.s3.amazonaws.com/75ed61524f55e542414d165ed60a976091c24f77/gradio-3.16.2-py3-none-any.whl
3
  pandas
4
  numpy
5
- datasets
 
 
2
  https://gradio-builds.s3.amazonaws.com/75ed61524f55e542414d165ed60a976091c24f77/gradio-3.16.2-py3-none-any.whl
3
  pandas
4
  numpy
5
+ datasets
6
+ wordcloud