{ "cells": [ { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "from IPython.display import HTML, display\n", "\n", "display(HTML('''\n", "^'''))\n", "print('')" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "#### PANORAMAS OF CINEMA online\n", "\n", "# // MOVIE SEARCH\n", "\n", "v0.01" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "code_folding": [] }, "outputs": [], "source": [ "# REQUEST INDEXES\n", "import requests\n", "r = requests.get(\"https://panoramas-of-cinema.s3.eu-central-1.amazonaws.com/indexes/videotheques_index.json\")\n", "movies = r.json()['index']\n", "button_color = 'black' # #7d1b27 darkRed\n", "print('\\n', '\\n', '\\n', '\\n', '\\n')" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "import ipywidgets as widgets\n", "index = widgets.Dropdown(\n", " options=movies,\n", " value=\"2001_a_space_odyssey\",\n", " description='MOVIE',\n", " disabled=False,\n", ")\n", "\n", "display(index)" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "print('\\n', '\\n', '\\n', '\\n', '\\n')" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## IMAGE NAVIGATION" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "code_folding": [] }, "outputs": [], "source": [ "from IPython.display import clear_output\n", "\n", "# PLOT SOM\n", "button_icons = ['„','‹','ˆ',\"'\",'~','˛','˝','¸','¯','•','º',\"˙\",'«','”','¨','˘']\n", "\n", "def plot_som(event):\n", " clear_output()\n", " display(plot_som_button)\n", " \n", " my_movie = '/'+index.value\n", " #print (index.value)\n", " \n", " import requests\n", " r = requests.get(\"https://panoramas-of-cinema.s3.eu-central-1.amazonaws.com/soms%s/contour-rgb.json\"%my_movie)\n", " global som_index\n", " som_index = r.json()\n", "\n", " how_many = 16\n", " plot_x, plot_y = 4,4\n", "\n", " # OPEN IMAGES ------------------------------\n", " import requests\n", " s3BucketName = \"panoramas-of-cinema\"\n", " region_name = 'eu-central-1'\n", "\n", " frames_plot = []\n", " for i in range(how_many):\n", " bmu = str(i)\n", " objectKey = \"soms%s/%s.jpg\"%(my_movie,bmu)\n", " this_frame = \"https://%s.s3.%s.amazonaws.com/%s\"%(s3BucketName,region_name,objectKey)\n", " r = requests.get(this_frame)\n", " if r.status_code == 200:\n", " img = r.content \n", " else:\n", " this_frame = \"https://%s.s3.%s.amazonaws.com/soms/empty_bmu.jpg\"%(s3BucketName,region_name)\n", " img = requests.get(this_frame).content\n", " frames_plot.append( (bmu, _, img) )\n", "\n", " # BUTTON EVENT ------------------------------\n", " def on_button_clicked(event):\n", " global bmu_2p\n", " this_button = id(event)\n", " all_buttons = my_som['w_buttons']\n", " for i, b in enumerate(all_buttons):\n", " this_id = id(b)\n", " if this_button == this_id:\n", " bmu_2p = my_som['w_buttons'][i].tooltip\n", " \n", " global my_globals_bmu\n", " my_globals_bmu = {'plotted':[], 'w_buttons':[]}\n", " \n", " # PLOT ------------------------------\n", " from ipywidgets import Button, HBox, VBox\n", " import ipywidgets as widgets\n", "\n", " k = 0\n", " movie_index, movie_names = 0, []\n", " vboxes = []\n", " for i in range(plot_x):\n", " this_col = []\n", " for j in range(plot_y):\n", " if k < len(frames_plot):\n", " try:\n", " image_w = widgets.Image(value=frames_plot[k][2], format='jpg', width=250) #height=400\n", " button = widgets.Button(description=button_icons[k], tooltip=frames_plot[k][0])\n", " my_som['w_buttons'].append(button)\n", "\n", " button.on_click( on_button_clicked )\n", "\n", " this_box = [image_w, button]\n", " this_col = this_col+this_box\n", "\n", " except:\n", " raise\n", " k+=1\n", "\n", " box = VBox( this_col )\n", " vboxes.append(box)\n", "\n", " display(HBox( vboxes ))\n", " \n", "my_som = {'plotted':[], 'w_buttons':[]}\n", "plot_som_button = widgets.Button(description=\"show map\", button_style='info')\n", "plot_som_button.style.button_color = button_color\n", "display(plot_som_button)\n", "plot_som_button.on_click(plot_som)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### > click on an image" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "code_folding": [] }, "outputs": [], "source": [ "# DISPLAY WIDGETS \n", "from IPython.display import display, clear_output\n", "from ipywidgets import interactive, interact\n", "import ipywidgets as widgets\n", "\n", "# PLOT RANDOM FRAMES\n", "def plot_frames_bmu(event):\n", " clear_output()\n", " display(plot_bmu_button)\n", " \n", " my_movie = '/'+index.value\n", " print (index.value, end=' ')\n", " \n", " how_many = 16\n", " plot_x, plot_y = 4,4\n", " my_frames = som_index[bmu_2p]\n", "\n", " if len(my_frames) < how_many:\n", " how_many = len(my_frames)\n", " \n", " this_sample = []\n", " print (\"%s\"%button_icons[int(bmu_2p)])\n", " for i in range(len(my_frames)):\n", " if len(my_globals_bmu['plotted']) == len(my_frames):\n", " my_globals_bmu['plotted'] = []\n", " print(\"...you've seen it all\")\n", " \n", " if i in my_globals_bmu['plotted']:\n", " pass\n", " else:\n", " this_sample.append(i)\n", " my_globals_bmu['plotted'].append(i)\n", " if len(my_globals_bmu['plotted']) == len(my_frames):\n", " print('...last batch')\n", " break\n", " if len(this_sample) == how_many:\n", " break \n", " \n", " \n", " # OPEN IMAGES ------------------------------\n", " import requests\n", " s3BucketName = \"panoramas-of-cinema\"\n", " region_name = 'eu-central-1'\n", "\n", " i=0\n", " frames_plot = []\n", " for frame in my_frames:\n", " if i in this_sample:\n", " try:\n", " objectKey = \"frames_db%s/by_scene_thumbnail%s\" % (my_movie, frame)\n", " this_frame = \"https://%s.s3.%s.amazonaws.com/%s\"%(s3BucketName,region_name,objectKey)\n", " img = requests.get(this_frame).content \n", " frames_plot.append( (my_movie, frame, img) )\n", " except:\n", " raise \n", " i+=1\n", "\n", " # PLOT ------------------------------\n", " def on_button_clicked(event):\n", " global movie_2p\n", " global frame_2p\n", " this_button = id(event)\n", " G = globals()\n", " all_buttons = G['my_globals_bmu']['w_buttons']\n", " for i, b in enumerate(all_buttons):\n", " this_id = id(b)\n", " if this_button == this_id:\n", " movie_2p = my_globals_bmu['w_buttons'][i].tooltip\n", " frame_2p = my_globals_bmu['w_buttons'][i].description\n", "\n", " print('...plotting %s images from %s'%(how_many, len(my_frames)))\n", " from ipywidgets import Button, HBox, VBox\n", " import ipywidgets as widgets\n", "\n", " k = 0\n", " movie_index, movie_names = 0, []\n", " vboxes = []\n", " for i in range(plot_x):\n", " this_col = []\n", " for j in range(plot_y):\n", " if k < len(frames_plot):\n", " try:\n", " image_w = widgets.Image(value=frames_plot[k][2], format='png', width=250) #height=400\n", " button = widgets.Button(description=frames_plot[k][1], tooltip=frames_plot[k][0])\n", " my_globals_bmu['w_buttons'].append(button)\n", "\n", " button.on_click( on_button_clicked )\n", "\n", " this_box = [image_w, button]\n", " this_col = this_col+this_box\n", "\n", " except:\n", " raise\n", " k+=1\n", "\n", " box = VBox( this_col )\n", " vboxes.append(box)\n", "\n", " display(HBox( vboxes ))\n", " \n", "plot_bmu_button = widgets.Button(description=\"navigate\", button_style='info')\n", "plot_bmu_button.style.button_color = button_color\n", "display(plot_bmu_button)\n", "plot_bmu_button.on_click(plot_frames_bmu)" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "print('\\n', '\\n', '\\n', '\\n', '\\n')" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## IMAGE SEARCH" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "def refresh_index(event):\n", " clear_output()\n", " \n", " my_movie = '/'+index.value\n", " r = requests.get(\"https://panoramas-of-cinema.s3.eu-central-1.amazonaws.com/inventories%s.json\"%my_movie)\n", " query_response = r.json()\n", " print (index.value)\n", " print ('')\n", " \n", " # SHOW PLACES \n", " print ('PLACES INDEX')\n", " for e in sorted(query_response['places']):\n", " print(e, end=' . ')\n", " print('')\n", " \n", " # SHOW INDEXES \n", " print ('')\n", " print ('')\n", " print ('OBJECTS INDEX')\n", " for e in sorted(query_response['objects']):\n", " print(e, end=' . ')\n", " print ('')\n", " print ('')\n", " \n", " display(refresh_index_button)\n", "\n", "refresh_index_button = widgets.Button(description=\"show indexes\", button_style='info')\n", "refresh_index_button.style.button_color = button_color\n", "display(refresh_index_button)\n", "refresh_index_button.on_click(refresh_index)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### > type the indexes and tune the confidences" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "# DISPLAY WIDGETS \n", "from IPython.display import display, clear_output\n", "from ipywidgets import interactive, interact\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", "def p(place, confidence):\n", " return\n", "\n", "def o(obj, confidence):\n", " return\n", "\n", "w_places = interactive(p, place='',\n", " confidence = widgets.SelectionRangeSlider(options=options, index=(0,99), description='confidence') )\n", "\n", "w_objects = interactive(o, obj='',\n", " confidence = widgets.SelectionRangeSlider(options=options, index=(0,99), description='confidence') )\n", "\n", "\n", "display(w_places)\n", "display(w_objects)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### > select the faces" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "def f(no_faces, yes_faces):\n", " return\n", "\n", "w_faces = interactive(f, no_faces=True, yes_faces=True)\n", "display(w_faces)" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "code_folding": [] }, "outputs": [], "source": [ "# REFRESH QUERY\n", "def refresh_query(event):\n", " clear_output()\n", " display(refresh_button)\n", " \n", " my_movie = '/'+index.value\n", " print (index.value)\n", " \n", " place = w_places.kwargs['place']\n", " place_conf = \"%s,%s\"%(w_places.kwargs['confidence'])\n", "\n", " obj = w_objects.kwargs['obj']\n", " obj_conf = \"%s,%s\"%(w_objects.kwargs['confidence'])\n", "\n", " faces = str()\n", " if w_faces.kwargs['no_faces']:\n", " faces = faces+'no_faces'\n", " if w_faces.kwargs['yes_faces']:\n", " if len(faces) > 0:\n", " faces = faces+',small_faces'\n", " else:\n", " faces = faces+'small_faces'\n", "\n", " # \n", " this_query = 'http://pocquery-env.eba-ap3n3cr3.eu-central-1.elasticbeanstalk.com/queryMovie?'\n", " if place: this_query = this_query+'places=%s,%s'%(place,place_conf)\n", " if faces: this_query = this_query+'&faces=%s'%faces\n", " if obj: this_query = this_query+'&objects=%s,%s'%(obj,obj_conf)\n", " this_query = this_query+'&movie=%s'%(my_movie[1:])\n", " \n", " global my_frames\n", " my_frames = requests.get(this_query).json()['response']\n", " print (len(my_frames), 'images with this search') # this_query[73:]\n", " \n", " global my_globals\n", " my_globals = {'plotted':[], 'w_buttons':[]}\n", "\n", " \n", "refresh_button = widgets.Button(description=\"search\", button_style='info')\n", "refresh_button.style.button_color = button_color\n", "display(refresh_button)\n", "refresh_button.on_click(refresh_query)" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "code_folding": [] }, "outputs": [], "source": [ "# PLOT RANDOM FRAMES\n", "def plot_frames(event):\n", " clear_output()\n", " display(plot_button)\n", " \n", " my_movie = '/'+index.value\n", "\n", " how_many = 16\n", " plot_x, plot_y = 4,4\n", "\n", " if len(my_frames) < how_many:\n", " how_many = len(my_frames)\n", "\n", " all_i = [ i for i in range(len(my_frames)) ]\n", "\n", " import random\n", " on_off = True\n", " this_sample = []\n", " while on_off:\n", " if len(my_globals['plotted']) == len(my_frames):\n", " my_globals['plotted'] = []\n", " print(\"...you've seen it all\")\n", " r = random.choice(all_i)\n", " if r in my_globals['plotted']:\n", " pass\n", " else:\n", " this_sample.append(r)\n", " my_globals['plotted'].append(r)\n", " if len(my_globals['plotted']) == len(my_frames):\n", " print('...last batch')\n", " break\n", " if len(this_sample) == how_many:\n", " break\n", "\n", " # OPEN IMAGES ------------------------------\n", " import requests\n", " s3BucketName = \"panoramas-of-cinema\"\n", " region_name = 'eu-central-1'\n", "\n", " i=0\n", " frames_plot = []\n", " for e in my_frames:\n", " film = e['movieId']\n", " frame = e['frameId']\n", " if i in this_sample:\n", " try:\n", " objectKey = \"frames_db%s/by_scene_thumbnail%s\" % (my_movie, frame)\n", " this_frame = \"https://%s.s3.%s.amazonaws.com/%s\"%(s3BucketName,region_name,objectKey)\n", " img = requests.get(this_frame).content \n", " frames_plot.append( (film, frame, img) )\n", " except:\n", " raise \n", " i+=1\n", "\n", " # PLOT ------------------------------\n", " def on_button_clicked(event):\n", " global movie_2p\n", " global frame_2p\n", " this_button = id(event)\n", " G = globals()\n", " all_buttons = G['my_globals']['w_buttons']\n", " for i, b in enumerate(all_buttons):\n", " this_id = id(b)\n", " if this_button == this_id:\n", " movie_2p = my_globals['w_buttons'][i].tooltip\n", " frame_2p = my_globals['w_buttons'][i].description\n", "\n", " print('...plotting %s images from %s'%(how_many, len(my_frames)))\n", " from ipywidgets import Button, HBox, VBox\n", " import ipywidgets as widgets\n", "\n", " k = 0\n", " movie_index, movie_names = 0, []\n", " vboxes = []\n", " for i in range(plot_x):\n", " this_col = []\n", " for j in range(plot_y):\n", " if k < len(frames_plot):\n", " try:\n", " image_w = widgets.Image(value=frames_plot[k][2], format='png', width=250) #height=400\n", " button = widgets.Button(description=frames_plot[k][1], tooltip=frames_plot[k][0])\n", " my_globals['w_buttons'].append(button)\n", "\n", " button.on_click( on_button_clicked )\n", "\n", " this_box = [image_w, button]\n", " this_col = this_col+this_box\n", "\n", " except:\n", " raise\n", " k+=1\n", "\n", " box = VBox( this_col )\n", " vboxes.append(box)\n", "\n", " display(HBox( vboxes ))\n", " \n", "plot_button = widgets.Button(description=\"show\", button_style='info')\n", "plot_button.style.button_color = button_color\n", "display(plot_button)\n", "plot_button.on_click(plot_frames)" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "print('\\n', '\\n', '\\n', '\\n', '\\n')" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## HQ IMAGE" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### > click on an image" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "from IPython.display import Image, display\n", "\n", "def get_hq_image(event):\n", " clear_output()\n", " display(hq_image_button)\n", " \n", " objectKey = \"frames_db%s/by_scene%s\" % (movie_2p, frame_2p)\n", " display(Image(url='https://panoramas-of-cinema.s3.eu-central-1.amazonaws.com/%s'%objectKey, width=450))\n", " print('%s%s'%(movie_2p[1:],frame_2p[6:-4]))\n", " \n", "hq_image_button = widgets.Button(description=\"hq image\", button_style='info')\n", "hq_image_button.style.button_color = button_color\n", "display(hq_image_button)\n", "hq_image_button.on_click(get_hq_image)" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "print('\\n', '\\n', '\\n', '\\n', '\\n')" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## PLAY A CLIP" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### > click on an image" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "scrolled": false }, "outputs": [], "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", " #print(r)\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": "markdown", "metadata": {}, "source": [ "

no sound ? try Safari ))

" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "print('\\n', '\\n', '\\n', '\\n', '\\n')" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## TEXT SEARCH" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### > type your query" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "# GLOBAL\n", "r = requests.get(\"https://panoramas-of-cinema.s3.eu-central-1.amazonaws.com/indexes/categories.json\")\n", "text_cat = r.json()\n", "\n", "# DISPLAY WIDGETS \n", "from IPython.display import display, clear_output\n", "from ipywidgets import interactive, interact\n", "import ipywidgets as widgets\n", "\n", "def search_text(text, confidence, max_results, c):\n", " return\n", "\n", "w_search_text = interactive(search_text, text='gone south',\n", " confidence=widgets.SelectionRangeSlider(options=options, index=(0,99), description='confidence'),\n", " max_results='10',\n", " c=widgets.HTML(description='categories', value=\">\", placeholder='')\n", " )\n", "\n", "display(w_search_text)\n" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "scrolled": false }, "outputs": [], "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 get_cat(movie):\n", " cat_names = ['SOLARIS MON AMOUR','EQUILIBRIUM OF AN OLDBOY',\n", " 'THE 400 CHILDREN OF LA HEINE','Y TU MAMA TAMBIEN DEPARTED']\n", " for k in text_cat:\n", " if movie in text_cat[k]:\n", " return ( int(k)+1, cat_names[int(k)] )\n", " \n", "def text_search(event):\n", " clear_output()\n", " display(search_button)\n", " \n", " # MAKE A QUERY ------------------------------\n", " text = format_text(w_search_text.kwargs['text'])\n", " confX = w_search_text.kwargs['confidence'][0]\n", " confY = w_search_text.kwargs['confidence'][1]\n", " max_results = w_search_text.kwargs['max_results']\n", " cat = get_cat('/'+index.value)\n", "\n", " app_http = 'http://ec2-3-127-150-33.eu-central-1.compute.amazonaws.com'\n", " this_query = app_http+'/subs?'\n", " if text: this_query = this_query+'text=%s&confidence_min=%s&confidence_max=%s'%(text,confX,confY)\n", " if max_results: this_query = this_query+'&maxResults=%s&category=%s'%(max_results,cat[0])\n", " #print(this_query)\n", " \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", " print ('')\n", " display( Label('˛ %s'%cat[1].lower()) )\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(text_search)" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "print('\\n', '\\n', '\\n', '\\n', '\\n')" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## YOUR TAGS" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### ADD" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### > click on an image. type its tag and your user name" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "tag_http = 'http://poctag-env.eba-vjpstfpz.eu-central-1.elasticbeanstalk.com/tags'\n", "\n", "# DISPLAY WIDGETS \n", "def getUser(user):\n", " return\n", "\n", "def getTag(tag):\n", " return\n", "\n", "w_user = interactive(getUser, user='')\n", "w_tag = interactive(getTag, tag='')\n", "\n", "# REFRESH QUERY\n", "def add_tag(event):\n", " clear_output()\n", " display(w_tag)\n", " display(w_user)\n", " display(add_tag_button)\n", " \n", " this_user = w_user.kwargs['user']\n", " this_tag = w_tag.kwargs['tag']\n", " this_frame = '%s,%s'%(movie_2p,frame_2p)\n", " this_request = tag_http+'?action=ADD&tag=%s&user=%s&frame=%s'%(this_tag,this_user,this_frame)\n", " r = requests.get(this_request).json()['statusCode']\n", " if r == 200: print('tag added to : %s %s'%(movie_2p, frame_2p))\n", " else: print ('error %s'%r)\n", "\n", "add_tag_button = widgets.Button(description=\"add tag\", button_style='info')\n", "add_tag_button.style.button_color = button_color\n", "add_tag_button.on_click(add_tag)\n", "\n", "display(w_tag)\n", "display(w_user)\n", "display(add_tag_button)" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "print('\\n', '\\n', '\\n', '\\n', '\\n')" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### SEARCH" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### users index" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "this_request = tag_http+'?action=GET_ALL_USERS'\n", "r = requests.get(this_request).json()['body']\n", "for e in sorted(r):\n", " print(e, end=' . ')\n", "\n", "print('')\n", "print('')\n", "\n", "def get_users(event):\n", " clear_output()\n", "\n", " this_request = tag_http+'?action=GET_ALL_USERS'\n", " r = requests.get(this_request).json()['body']\n", " for e in sorted(r):\n", " print(e, end=' . ')\n", " \n", " display(refresh_users_button)\n", "\n", " \n", "refresh_users_button = widgets.Button(description=\"refresh users\", button_style='info')\n", "refresh_users_button.style.button_color = button_color\n", "display(refresh_users_button)\n", "refresh_users_button.on_click(get_users)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### > type a tag and/or user" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "# BOXES \n", "def getUserSearch(user_search):\n", " return\n", "\n", "def getTagSearch(tag_search):\n", " return\n", "\n", "w_user_search = interactive(getUserSearch, user_search='')\n", "w_tag_search = interactive(getTagSearch, tag_search='')\n", "\n", "# BUTTON\n", "def search_tag(event):\n", " clear_output()\n", " display(w_tag_search)\n", " display(w_user_search)\n", " display(search_tag_button)\n", " \n", " this_user = w_user_search.kwargs['user_search']\n", " this_tag = w_tag_search.kwargs['tag_search']\n", " \n", " global my_frames_tag\n", " if len(this_user) > 0 and len(this_tag) > 0:\n", " this_request = tag_http+'?action=GET_FRAMES_USER_TAG&tag=%s&user=%s'%(this_tag,this_user)\n", " my_frames_tag = requests.get(this_request).json()\n", " this_length = len(my_frames_tag['body'])\n", " print (this_length, 'images with this search')\n", " elif len(this_user) > 0 and len(this_tag) == 0:\n", " this_request = tag_http+'?action=GET_FRAMES_USER&user=%s'%(this_user)\n", " my_frames_tag = requests.get(this_request).json()\n", " this_length = len(my_frames_tag['body'])\n", " print (this_length, 'images with this search')\n", " this_tags = set([ f['tag'] for f in my_frames_tag['body'] ])\n", " print (this_user, 'is talking about . ', end='')\n", " for e in sorted(this_tags): print(e, end=' . ')\n", " elif len(this_user) == 0 and len(this_tag) > 0:\n", " this_request = tag_http+'?action=GET_FRAMES_TAG&tag=%s'%(this_tag)\n", " my_frames_tag = requests.get(this_request).json()\n", " this_length = len(my_frames_tag['body'])\n", " print (this_length, 'images with this search')\n", " this_users = set([ f['user'] for f in my_frames_tag['body'] ])\n", " print (this_tag, 'is talked about by . ', end='')\n", " for e in sorted(this_users): print(e, end=' . ')\n", " else:\n", " print ('type a user name and/or a tag')\n", " \n", " global my_globals_tag\n", " my_globals_tag = {'plotted':[], 'w_buttons':[]}\n", " \n", "search_tag_button = widgets.Button(description=\"search tag\", button_style='info')\n", "search_tag_button.style.button_color = button_color\n", "search_tag_button.on_click(search_tag)\n", "\n", "display(w_tag_search)\n", "display(w_user_search)\n", "display(search_tag_button)" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "# PLOT RANDOM FRAMES \n", "def plot_frames_tags(event):\n", " clear_output()\n", " display(plot_button_tags)\n", " \n", " my_frames = my_frames_tag['body']\n", " how_many = 16\n", " plot_x, plot_y = 4,4\n", "\n", " if len(my_frames) < how_many:\n", " how_many = len(my_frames)\n", "\n", " all_i = [ i for i in range(len(my_frames)) ]\n", "\n", " import random\n", " on_off = True\n", " this_sample = []\n", " while on_off:\n", " if len(my_globals_tag['plotted']) == len(my_frames):\n", " my_globals_tag['plotted'] = []\n", " print(\"...you've seen it all\")\n", " r = random.choice(all_i)\n", " if r in my_globals_tag['plotted']:\n", " pass\n", " else:\n", " this_sample.append(r)\n", " my_globals_tag['plotted'].append(r)\n", " if len(my_globals_tag['plotted']) == len(my_frames):\n", " print('...last batch')\n", " break\n", " if len(this_sample) == how_many:\n", " break\n", "\n", " # OPEN IMAGES ------------------------------\n", " import requests\n", "\n", " s3BucketName = \"panoramas-of-cinema\"\n", " region_name = 'eu-central-1'\n", "\n", " i=0\n", " frames_plot = []\n", " for e in my_frames:\n", " film = e['movie']\n", " frame = e['frame']\n", " if i in this_sample:\n", " try:\n", " objectKey = \"frames_db%s/by_scene_thumbnail%s\" % (film, frame)\n", " this_frame = \"https://%s.s3.%s.amazonaws.com/%s\"%(s3BucketName,region_name,objectKey)\n", " img = requests.get(this_frame).content \n", " frames_plot.append( (film, frame, img) )\n", " except:\n", " raise \n", " i+=1\n", "\n", " # PLOT ------------------------------\n", " def on_button_clicked(event):\n", " global movie_2p_tag, frame_2p_tag\n", " global movie_2p, frame_2p\n", " \n", " this_button = id(event)\n", " G = globals()\n", " all_buttons = G['my_globals_tag']['w_buttons']\n", " for i, b in enumerate(all_buttons):\n", " this_id = id(b)\n", " if this_button == this_id:\n", " movie_2p_tag = my_globals_tag['w_buttons'][i].description\n", " frame_2p_tag = my_globals_tag['w_buttons'][i].tooltip\n", " movie_2p = my_globals_tag['w_buttons'][i].description\n", " frame_2p = my_globals_tag['w_buttons'][i].tooltip\n", " \n", " print('...plotting %s images from %s'%(how_many, len(my_frames)))\n", " from ipywidgets import Button, HBox, VBox\n", " import ipywidgets as widgets\n", "\n", " k = 0\n", " movie_index, movie_names = 0, []\n", " vboxes = []\n", " for i in range(plot_x):\n", " this_col = []\n", " for j in range(plot_y):\n", " if k < len(frames_plot):\n", " try:\n", " image_w = widgets.Image(value=frames_plot[k][2], format='png', width=250) #height=400\n", " button = widgets.Button(description=frames_plot[k][0], tooltip=frames_plot[k][1])\n", " my_globals_tag['w_buttons'].append(button)\n", "\n", " button.on_click( on_button_clicked )\n", "\n", " this_box = [image_w, button]\n", " this_col = this_col+this_box\n", "\n", " except:\n", " raise\n", " k+=1\n", "\n", " box = VBox( this_col )\n", " vboxes.append(box)\n", "\n", " display(HBox( vboxes ))\n", " \n", "plot_button_tags = widgets.Button(description=\"show\", button_style='info')\n", "plot_button_tags.style.button_color = button_color\n", "display(plot_button_tags)\n", "plot_button_tags.on_click(plot_frames_tags)" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "print('\\n', '\\n', '\\n', '\\n', '\\n')" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### DELETE" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### > click on an image" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "def delete_tag(event):\n", " clear_output()\n", " display(delete_tag_button)\n", " \n", " this_user = w_user_search.kwargs['user_search']\n", " this_tag = w_tag_search.kwargs['tag_search']\n", " if len(this_user) > 0 and len(this_tag) > 0:\n", " this_frame = '%s,%s'%(movie_2p_tag,frame_2p_tag)\n", " this_request = tag_http+'?action=DELETE&tag=%s&user=%s&frame=%s'%(this_tag,this_user,this_frame)\n", " r = requests.get(this_request).json()['statusCode']\n", " if r == 200: print('tag deleted : %s %s'%(movie_2p_tag, frame_2p_tag))\n", " else: print ('error %s'%r)\n", " else:\n", " print ('! user or tag is missing')\n", "\n", " \n", "delete_tag_button = widgets.Button(description=\"delete\", button_style='info')\n", "delete_tag_button.style.button_color = button_color\n", "display(delete_tag_button)\n", "delete_tag_button.on_click(delete_tag)" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "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 }