Spaces:
Runtime error
Runtime error
Upload app.py
Browse files
app.py
ADDED
@@ -0,0 +1,199 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
import requests
|
3 |
+
|
4 |
+
SERVERLESS_URL = "https://pepe-semantics-vdn32ryg7q-uc.a.run.app/predict"
|
5 |
+
|
6 |
+
gTop = []
|
7 |
+
linkTop = []
|
8 |
+
|
9 |
+
|
10 |
+
def predict(text):
|
11 |
+
global gTop
|
12 |
+
global linkTop
|
13 |
+
|
14 |
+
r = requests.post(SERVERLESS_URL, json={"text": text})
|
15 |
+
dic = r.json()
|
16 |
+
links = eval(dic["result"])
|
17 |
+
gTop = links[:5]
|
18 |
+
|
19 |
+
linkTop = []
|
20 |
+
for link in gTop:
|
21 |
+
path = "![ALT TEXT](" + link + ")"
|
22 |
+
linkTop.append(path)
|
23 |
+
|
24 |
+
return linkTop
|
25 |
+
|
26 |
+
|
27 |
+
callback = gr.CSVLogger()
|
28 |
+
|
29 |
+
css_bg_img = ".gradio-container {background-image: url('file=https://i.kym-cdn.com/photos/images/original/001/440/489/55b.png'); background-position: center;}"
|
30 |
+
|
31 |
+
|
32 |
+
with gr.Blocks(css=css_bg_img) as demo:
|
33 |
+
gr.Markdown(
|
34 |
+
"""<h1 style='text-align: center;'><span style="background-color:white;">PEPE-Sematics</span></h1>"""
|
35 |
+
)
|
36 |
+
gr.Markdown(
|
37 |
+
"""
|
38 |
+
<p style="text-align:center;background-color: #FFFFFF" ><b>The world of GIFs needs saviour. While it has initially thrived on the legacy
|
39 |
+
of a few GIFs, the Gifverse is becoming chaotic and it is becoming very difficult to find good Gifs.
|
40 |
+
Swoops in PEPE-Sematic to help those in need.<b></p>
|
41 |
+
|
42 |
+
<center>
|
43 |
+
<iframe src="https://giphy.com/embed/rBSB0tULImCv9DJi1P" width="480" height="361" frameBorder="0" class="giphy-embed" allowFullScreen></iframe></p>
|
44 |
+
</center>
|
45 |
+
<p style="text-align:center;background-color: #FFFFFF"> PEPE-Sematics adopts from the <a href="https://github.com/xingyaoww/gif-reply" style='color:blue'>PEPE model</a>
|
46 |
+
and uses MLOps to bring it to your browser. PEPE-Sematics present to you multiple recommendations to choose from.
|
47 |
+
As fellow Giffer's we know it is never enough unless you spam your bae or friend or an annoying colleague, thus multiple
|
48 |
+
recommedations is the only way to go about it. To ease your confusion we also provide a top recommendation based on our
|
49 |
+
algorithm.</p>
|
50 |
+
"""
|
51 |
+
)
|
52 |
+
|
53 |
+
gr.Markdown(
|
54 |
+
"""<center><h2><span style="background-color:white;">Test it out</span></h2><center>"""
|
55 |
+
)
|
56 |
+
|
57 |
+
text_input = gr.Textbox(
|
58 |
+
label="Input", placeholder="Type something to get cool gifs \N{smile}"
|
59 |
+
)
|
60 |
+
with gr.Row():
|
61 |
+
submit_button = gr.Button("Submit")
|
62 |
+
|
63 |
+
with gr.Row():
|
64 |
+
gr.Markdown(
|
65 |
+
"""<center><h2><span style="background-color:white;">Top Recommedation</span></h2><center>"""
|
66 |
+
)
|
67 |
+
with gr.Row():
|
68 |
+
image0 = gr.Markdown(
|
69 |
+
"<iframe src='https://giphy.com/embed/1YeNJK6FptDdq1q59K' width='480' height='280' frameBorder='0' class='giphy-embed' allowFullScreen></iframe>"
|
70 |
+
)
|
71 |
+
with gr.Row():
|
72 |
+
image0_up = gr.Button("\N{thumbs up sign}")
|
73 |
+
image0_down = gr.Button("\N{thumbs down sign}")
|
74 |
+
image0_flag = gr.Button("Flag")
|
75 |
+
gr.Markdown(
|
76 |
+
"""<center><h2><span style="background-color:white;">Recommended GIFs</span></h2><center>"""
|
77 |
+
)
|
78 |
+
with gr.Row():
|
79 |
+
with gr.Column(scale=1, min_width=300):
|
80 |
+
image1 = gr.Markdown(
|
81 |
+
"<iframe src='https://giphy.com/embed/enCWEo0vG25Ow' width='300' height='280' frameBorder='0' class='giphy-embed' allowFullScreen></iframe>"
|
82 |
+
)
|
83 |
+
with gr.Row():
|
84 |
+
image1_up = gr.Button("\N{thumbs up sign}")
|
85 |
+
image1_down = gr.Button("\N{thumbs down sign}")
|
86 |
+
image1_flag = gr.Button("Flag")
|
87 |
+
with gr.Column(scale=1, min_width=300):
|
88 |
+
image2 = gr.Markdown(
|
89 |
+
"<iframe src='https://giphy.com/embed/l41YouCUUcreUabHW' width='300' height='280' frameBorder='0' class='giphy-embed' allowFullScreen></iframe>"
|
90 |
+
)
|
91 |
+
with gr.Row():
|
92 |
+
image2_up = gr.Button("\N{thumbs up sign}")
|
93 |
+
image2_down = gr.Button("\N{thumbs down sign}")
|
94 |
+
image2_flag = gr.Button("Flag")
|
95 |
+
with gr.Column(scale=1, min_width=300):
|
96 |
+
image3 = gr.Markdown(
|
97 |
+
"<iframe src='https://giphy.com/embed/SJWZDnQfQe46YAvIxj' width='300' height='280' frameBorder='0' class='giphy-embed' allowFullScreen></iframe>"
|
98 |
+
)
|
99 |
+
with gr.Row():
|
100 |
+
image3_up = gr.Button("\N{thumbs up sign}")
|
101 |
+
image3_down = gr.Button("\N{thumbs down sign}")
|
102 |
+
image3_flag = gr.Button("Flag")
|
103 |
+
with gr.Column(scale=1, min_width=300):
|
104 |
+
image4 = gr.Markdown(
|
105 |
+
"<iframe src='https://giphy.com/embed/g7GKcSzwQfugw' width='300' height='280' frameBorder='0' class='giphy-embed' allowFullScreen></iframe>"
|
106 |
+
)
|
107 |
+
with gr.Row():
|
108 |
+
image4_up = gr.Button("\N{thumbs up sign}")
|
109 |
+
image4_down = gr.Button("\N{thumbs down sign}")
|
110 |
+
image4_flag = gr.Button("Flag")
|
111 |
+
|
112 |
+
outputs = submit_button.click(
|
113 |
+
predict,
|
114 |
+
inputs=text_input,
|
115 |
+
outputs=[image0, image1, image2, image3, image4],
|
116 |
+
scroll_to_output=True,
|
117 |
+
)
|
118 |
+
|
119 |
+
print(outputs)
|
120 |
+
|
121 |
+
callback.setup([text_input], "flagged_data")
|
122 |
+
|
123 |
+
image1_up.click(
|
124 |
+
lambda *args: callback.flag(args, flag_option="Up", username=gTop[1]),
|
125 |
+
[text_input],
|
126 |
+
None,
|
127 |
+
)
|
128 |
+
image2_up.click(
|
129 |
+
lambda *args: callback.flag(args, flag_option="Up", username=gTop[2]),
|
130 |
+
[text_input],
|
131 |
+
None,
|
132 |
+
)
|
133 |
+
image3_up.click(
|
134 |
+
lambda *args: callback.flag(args, flag_option="Up", username=gTop[3]),
|
135 |
+
[text_input],
|
136 |
+
None,
|
137 |
+
)
|
138 |
+
image4_up.click(
|
139 |
+
lambda *args: callback.flag(args, flag_option="Up", username=gTop[4]),
|
140 |
+
[text_input],
|
141 |
+
None,
|
142 |
+
)
|
143 |
+
image0_up.click(
|
144 |
+
lambda *args: callback.flag(args, flag_option="Up", username=gTop[0]),
|
145 |
+
[text_input],
|
146 |
+
None,
|
147 |
+
)
|
148 |
+
image1_down.click(
|
149 |
+
lambda *args: callback.flag(args, flag_option="Down", username=gTop[1]),
|
150 |
+
[text_input],
|
151 |
+
None,
|
152 |
+
)
|
153 |
+
image2_down.click(
|
154 |
+
lambda *args: callback.flag(args, flag_option="Down", username=gTop[2]),
|
155 |
+
[text_input],
|
156 |
+
None,
|
157 |
+
)
|
158 |
+
image3_down.click(
|
159 |
+
lambda *args: callback.flag(args, flag_option="Down", username=gTop[3]),
|
160 |
+
[text_input],
|
161 |
+
None,
|
162 |
+
)
|
163 |
+
image4_down.click(
|
164 |
+
lambda *args: callback.flag(args, flag_option="Down", username=gTop[4]),
|
165 |
+
[text_input],
|
166 |
+
None,
|
167 |
+
)
|
168 |
+
image0_down.click(
|
169 |
+
lambda *args: callback.flag(args, flag_option="Down", username=gTop[0]),
|
170 |
+
[text_input],
|
171 |
+
None,
|
172 |
+
)
|
173 |
+
image1_flag.click(
|
174 |
+
lambda *args: callback.flag(args, flag_option="Flag", username=gTop[1]),
|
175 |
+
[text_input],
|
176 |
+
None,
|
177 |
+
)
|
178 |
+
image2_flag.click(
|
179 |
+
lambda *args: callback.flag(args, flag_option="Flag", username=gTop[2]),
|
180 |
+
[text_input],
|
181 |
+
None,
|
182 |
+
)
|
183 |
+
image3_flag.click(
|
184 |
+
lambda *args: callback.flag(args, flag_option="Flag", username=gTop[3]),
|
185 |
+
[text_input],
|
186 |
+
None,
|
187 |
+
)
|
188 |
+
image4_flag.click(
|
189 |
+
lambda *args: callback.flag(args, flag_option="Flag", username=gTop[4]),
|
190 |
+
[text_input],
|
191 |
+
None,
|
192 |
+
)
|
193 |
+
image0_flag.click(
|
194 |
+
lambda *args: callback.flag(args, flag_option="Flag", username=gTop[0]),
|
195 |
+
[text_input],
|
196 |
+
None,
|
197 |
+
)
|
198 |
+
|
199 |
+
demo.launch(debug=False, share=True)
|