{
"cells": [
{
"cell_type": "code",
"execution_count": 1,
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"\n",
"toggle the code of this notebook on/off ^"
],
"text/plain": [
""
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"from IPython.display import HTML, display\n",
"\n",
"display(HTML('''\n",
"toggle the code of this notebook on/off ^'''))"
]
},
{
"cell_type": "markdown",
"metadata": {
"slideshow": {
"slide_type": "-"
}
},
"source": [
"### PANORAMAS OF CINEMA online"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# // SUBTITLES SEARCH\n",
"v0.02"
]
},
{
"cell_type": "code",
"execution_count": 2,
"metadata": {},
"outputs": [],
"source": [
"# GLOBAL\n",
"app_http = 'http://ec2-3-127-150-33.eu-central-1.compute.amazonaws.com'\n",
"button_color = 'black' # #7d1b27"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## SEARCH THE VIDEOTHEQUE"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### > type your query"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "code",
"execution_count": 3,
"metadata": {},
"outputs": [
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "2123b09497cf4a238ac728ddd3ee8eda",
"version_major": 2,
"version_minor": 0
},
"text/plain": [
"VBox(children=(Text(value='drops of blood', description='text', placeholder=''), SelectionRangeSlider(descript…"
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"# DISPLAY WIDGETS \n",
"from IPython.display import display, clear_output\n",
"from ipywidgets import interactive, interact, interactive_output\n",
"import ipywidgets as widgets\n",
"\n",
"options = []\n",
"s=0.01\n",
"for i in range(100):\n",
" options.append(\"%.2f\"%s)\n",
" s+=.01\n",
"\n",
"text_q = widgets.Text(value='drops of blood', placeholder='', description='text')\n",
"confidence = widgets.SelectionRangeSlider(options=options, index=(0,99), description='confidence')\n",
"cat = widgets.Dropdown(options=[('videotheque', 0),\n",
" ('solaris mon amour', 1),\n",
" ('equilibrium of an oldboy', 2),\n",
" ('the 400 children of la haine', 3),\n",
" ('y tu mama tambien departed', 4)],\n",
" value=0, description='category')\n",
"max_results_q = widgets.Text(value='10', placeholder='', description='max results')\n",
"hlink = widgets.HTML(description='', value=\" >\", placeholder='')\n",
"uiH = widgets.HBox([cat, hlink])\n",
"uiV = widgets.VBox([text_q, confidence, uiH, max_results_q])\n",
"\n",
"display(uiV)\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "code",
"execution_count": 4,
"metadata": {
"scrolled": false
},
"outputs": [
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "b4b82c5ad3ec4270bb4764a1d29afb36",
"version_major": 2,
"version_minor": 0
},
"text/plain": [
"Button(button_style='info', description='search', style=ButtonStyle(button_color='black'))"
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"# REFRESH QUERY\n",
"import requests, ast\n",
"\n",
"def format_text(query):\n",
" this_query = query.replace(' ', '%20')\n",
" return this_query\n",
" \n",
"def refresh_query(event):\n",
" clear_output()\n",
" display(search_button)\n",
" \n",
" text = format_text(text_q.value)\n",
" confX = confidence.value[0]\n",
" confY = confidence.value[1]\n",
" max_results = max_results_q.value\n",
" this_cat = cat.value\n",
"\n",
" # \n",
" this_query = app_http+'/subs?'\n",
" if text: this_query = this_query+'text=%s&confidence_min=%s&confidence_max=%s&category=%s'%(text,confX,confY,this_cat)\n",
" if max_results: this_query = this_query+'&maxResults=%s'%max_results\n",
" #print(this_query)\n",
" \n",
" #global my_text\n",
" my_text = ast.literal_eval(requests.get(this_query).text)['body']\n",
" if len(my_text) == 0:\n",
" print ('nothing here')\n",
" return \n",
" \n",
" # BUTTON EVENT ------------------------------\n",
" def on_button_clicked(event):\n",
" global movie_2p\n",
" global frame_2p\n",
" this_button = id(event)\n",
" for i, b in enumerate(buttons_text):\n",
" this_id = id(b)\n",
" if this_button == this_id:\n",
" movie_2p = buttons_text[i].description\n",
" frame_2p = '/frame-%06d.jpg'%float(buttons_text[i].tooltip)\n",
" \n",
" # DISPLAY THE RESULTS ------------------------------\n",
" from ipywidgets import VBox, Label, Button\n",
" \n",
" # formatting\n",
" texts_results = []\n",
" for movie, timestamp, prev, this, nex in my_text:\n",
" this_text = prev+' '+this+' '+nex\n",
" texts_results+=[this_text]\n",
" \n",
" # widgets\n",
" global buttons_text\n",
" buttons_text = []\n",
" \n",
" items = []\n",
" for i, t in enumerate(texts_results):\n",
" button = Button(description=my_text[i][0], tooltip=str(my_text[i][1]))\n",
" buttons_text.append(button)\n",
" button.on_click( on_button_clicked )\n",
" \n",
" items.append(Label(' '))\n",
" items.append(Label(t.lower()))\n",
" hlink = widgets.HTML(description='', value=\" >\"%my_text[i][0], placeholder='')\n",
" uiH = widgets.HBox([button, hlink])\n",
" items.append(uiH)\n",
" \n",
" display( VBox(items) )\n",
"\n",
" \n",
"search_button = widgets.Button(description=\"search\", button_style='info')\n",
"search_button.style.button_color = button_color\n",
"display(search_button)\n",
"search_button.on_click(refresh_query)"
]
},
{
"cell_type": "code",
"execution_count": 5,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"\n",
" \n",
" \n",
" \n",
" \n",
"\n"
]
}
],
"source": [
"print('\\n', '\\n', '\\n', '\\n', '\\n')"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## PLAY A CLIP"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### > click on a dialogue"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "code",
"execution_count": 6,
"metadata": {},
"outputs": [
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "04615e84bc2444518baf89835291909a",
"version_major": 2,
"version_minor": 0
},
"text/plain": [
"HBox(children=(Button(button_style='info', description='<<<', style=ButtonStyle(button_color='black')), Button…"
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"# PLAY THE CLIP \n",
"def play_clip(event):\n",
" clear_output()\n",
" display(ui1)\n",
"\n",
" global r\n",
" clip_query = 'http://pocgetclip-env.eba-4phq6b4m.eu-central-1.elasticbeanstalk.com/clip?movie=%s&frame=%s'%(movie_2p[1:],frame_2p[7:-4])\n",
" r = requests.get(clip_query).json()\n",
"\n",
" from IPython.display import Video\n",
" display(Video(r['play'], height=300, html_attributes=\"controls autoplay\"))\n",
" print('%s%s'%(movie_2p[1:],frame_2p[6:-4]))\n",
" \n",
"def play_before(event):\n",
" clear_output()\n",
" display(ui1)\n",
" \n",
" from IPython.display import Video\n",
" display(Video(r['before'], height=300, html_attributes=\"controls autoplay\"))\n",
" this_f = r['before'].find('frame-')\n",
" print('%s%s'%(movie_2p[1:],r['before'][(this_f)+5:-4]))\n",
" \n",
"def play_after(event):\n",
" clear_output()\n",
" display(ui1)\n",
" \n",
" from IPython.display import Video\n",
" display(Video(r['after'], height=300, html_attributes=\"controls autoplay\"))\n",
" this_f = r['after'].find('frame-')\n",
" print('%s%s'%(movie_2p[1:],r['after'][(this_f)+5:-4]))\n",
"\n",
"# buttons box\n",
"play_button = widgets.Button(description=\"play\", button_style='info')\n",
"play_button.style.button_color = button_color\n",
"playB_button = widgets.Button(description=\"<<<\", button_style='info')\n",
"playB_button.style.button_color = button_color\n",
"playA_button = widgets.Button(description=\">>>\", button_style='info')\n",
"playA_button.style.button_color = button_color\n",
"ui1 = widgets.HBox([playB_button, play_button, playA_button])\n",
"display(ui1)\n",
"\n",
"\n",
"play_button.on_click(play_clip)\n",
"playB_button.on_click(play_before)\n",
"playA_button.on_click(play_after)"
]
},
{
"cell_type": "code",
"execution_count": 7,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"\n",
" \n",
" \n",
" \n",
" \n",
"\n"
]
}
],
"source": [
"print('\\n', '\\n', '\\n', '\\n', '\\n')"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"ETH Zurich Department of Architecture Chair for Digital Architectonics 2021"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.7.6"
}
},
"nbformat": 4,
"nbformat_minor": 4
}