Skip to content

Commit 4e57017

Browse files
authored
fix device widget rendering (#2707)
1 parent d29aba6 commit 4e57017

File tree

32 files changed

+413
-434
lines changed

32 files changed

+413
-434
lines changed

notebooks/blip-visual-language-processing/blip-visual-language-processing.ipynb

+6-6
Original file line numberDiff line numberDiff line change
@@ -200,6 +200,11 @@
200200
" open(\"notebook_utils.py\", \"w\").write(r.text)\n",
201201
"from notebook_utils import download_file, device_widget, quantization_widget\n",
202202
"\n",
203+
"# Read more about telemetry collection at https://github.com/openvinotoolkit/openvino_notebooks?tab=readme-ov-file#-telemetry\n",
204+
"from notebook_utils import collect_telemetry\n",
205+
"\n",
206+
"collect_telemetry(\"blip-visual-language-processing.ipynb\")\n",
207+
"\n",
203208
"# get model and processor\n",
204209
"processor = BlipProcessor.from_pretrained(\"Salesforce/blip-vqa-base\")\n",
205210
"model = BlipForQuestionAnswering.from_pretrained(\"Salesforce/blip-vqa-base\")\n",
@@ -219,12 +224,7 @@
219224
"end = time.perf_counter() - start\n",
220225
"\n",
221226
"# postprocess result\n",
222-
"answer = processor.decode(out[0], skip_special_tokens=True)\n",
223-
"\n",
224-
"# Read more about telemetry collection at https://github.com/openvinotoolkit/openvino_notebooks?tab=readme-ov-file#-telemetry\n",
225-
"from notebook_utils import collect_telemetry\n",
226-
"\n",
227-
"collect_telemetry(\"blip-visual-language-processing.ipynb\")"
227+
"answer = processor.decode(out[0], skip_special_tokens=True)"
228228
]
229229
},
230230
{

notebooks/depth-anything/depth-anything.ipynb

+13-14
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,18 @@
6969
" r = requests.get(\n",
7070
" url=\"https://raw.githubusercontent.com/openvinotoolkit/openvino_notebooks/latest/utils/cmd_helper.py\",\n",
7171
" )\n",
72-
" open(\"cmd_helper.py\", \"w\").write(r.text)"
72+
" open(\"cmd_helper.py\", \"w\").write(r.text)\n",
73+
"\n",
74+
"if not Path(\"notebook_utils.py\").exists():\n",
75+
" r = requests.get(\n",
76+
" url=\"https://raw.githubusercontent.com/openvinotoolkit/openvino_notebooks/latest/utils/notebook_utils.py\",\n",
77+
" )\n",
78+
" open(\"notebook_utils.py\", \"w\").write(r.text)\n",
79+
"\n",
80+
"# Read more about telemetry collection at https://github.com/openvinotoolkit/openvino_notebooks?tab=readme-ov-file#-telemetry\n",
81+
"from notebook_utils import collect_telemetry\n",
82+
"\n",
83+
"collect_telemetry(\"depth-anything.ipynb\")"
7384
]
7485
},
7586
{
@@ -224,13 +235,6 @@
224235
"source": [
225236
"from PIL import Image\n",
226237
"\n",
227-
"if not Path(\"notebook_utils.py\").exists():\n",
228-
" r = requests.get(\n",
229-
" url=\"https://raw.githubusercontent.com/openvinotoolkit/openvino_notebooks/latest/utils/notebook_utils.py\",\n",
230-
" )\n",
231-
" open(\"notebook_utils.py\", \"w\").write(r.text)\n",
232-
"\n",
233-
"\n",
234238
"from notebook_utils import download_file, device_widget, quantization_widget\n",
235239
"\n",
236240
"if not Path(\"furseal.png\").exists():\n",
@@ -239,12 +243,7 @@
239243
" \"furseal.png\",\n",
240244
" )\n",
241245
"\n",
242-
"Image.open(\"furseal.png\").resize((600, 400))\n",
243-
"\n",
244-
"# Read more about telemetry collection at https://github.com/openvinotoolkit/openvino_notebooks?tab=readme-ov-file#-telemetry\n",
245-
"from notebook_utils import collect_telemetry\n",
246-
"\n",
247-
"collect_telemetry(\"depth-anything.ipynb\")"
246+
"Image.open(\"furseal.png\").resize((600, 400))"
248247
]
249248
},
250249
{

notebooks/encodec-audio-compression/encodec-audio-compression.ipynb

+18-16
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,23 @@
113113
"import torch\n",
114114
"import typing as tp\n",
115115
"\n",
116+
"# Fetch `notebook_utils` module\n",
117+
"import requests\n",
118+
"from pathlib import Path\n",
119+
"\n",
120+
"if not Path(\"notebook_utils.py\").exists():\n",
121+
" r = requests.get(\n",
122+
" url=\"https://raw.githubusercontent.com/openvinotoolkit/openvino_notebooks/latest/utils/notebook_utils.py\",\n",
123+
" )\n",
124+
"\n",
125+
" open(\"notebook_utils.py\", \"w\").write(r.text)\n",
126+
"\n",
127+
"\n",
128+
"# Read more about telemetry collection at https://github.com/openvinotoolkit/openvino_notebooks?tab=readme-ov-file#-telemetry\n",
129+
"from notebook_utils import collect_telemetry\n",
130+
"\n",
131+
"collect_telemetry(\"encodec-audio-compression.ipynb\")\n",
132+
"\n",
116133
"model_id = \"encodec_24khz\"\n",
117134
"# Instantiate a pretrained EnCodec model\n",
118135
"model = MODELS[model_id]()\n",
@@ -179,16 +196,6 @@
179196
"import librosa.display\n",
180197
"import IPython.display as ipd\n",
181198
"\n",
182-
"# Fetch `notebook_utils` module\n",
183-
"import requests\n",
184-
"from pathlib import Path\n",
185-
"\n",
186-
"if not Path(\"notebook_utils.py\").exists():\n",
187-
" r = requests.get(\n",
188-
" url=\"https://raw.githubusercontent.com/openvinotoolkit/openvino_notebooks/latest/utils/notebook_utils.py\",\n",
189-
" )\n",
190-
"\n",
191-
" open(\"notebook_utils.py\", \"w\").write(r.text)\n",
192199
"from notebook_utils import download_file, device_widget\n",
193200
"\n",
194201
"test_data_url = \"https://github.com/facebookresearch/encodec/raw/main/test_24k.wav\"\n",
@@ -200,12 +207,7 @@
200207
"plt.figure(figsize=(14, 5))\n",
201208
"librosa.display.waveshow(audio, sr=sr)\n",
202209
"\n",
203-
"ipd.Audio(sample_file)\n",
204-
"\n",
205-
"# Read more about telemetry collection at https://github.com/openvinotoolkit/openvino_notebooks?tab=readme-ov-file#-telemetry\n",
206-
"from notebook_utils import collect_telemetry\n",
207-
"\n",
208-
"collect_telemetry(\"encodec-audio-compression.ipynb\")"
210+
"ipd.Audio(sample_file)"
209211
]
210212
},
211213
{

notebooks/grammar-correction/grammar-correction.ipynb

+15-16
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,20 @@
176176
],
177177
"source": [
178178
"from transformers import pipeline, AutoTokenizer\n",
179-
"from optimum.intel.openvino import OVModelForSeq2SeqLM, OVModelForSequenceClassification"
179+
"from optimum.intel.openvino import OVModelForSeq2SeqLM, OVModelForSequenceClassification\n",
180+
"import requests\n",
181+
"from pathlib import Path\n",
182+
"\n",
183+
"if not Path(\"notebook_utils.py\").exists():\n",
184+
" r = requests.get(\n",
185+
" url=\"https://raw.githubusercontent.com/openvinotoolkit/openvino_notebooks/latest/utils/notebook_utils.py\",\n",
186+
" )\n",
187+
" open(\"notebook_utils.py\", \"w\").write(r.text)\n",
188+
"\n",
189+
"# Read more about telemetry collection at https://github.com/openvinotoolkit/openvino_notebooks?tab=readme-ov-file#-telemetry\n",
190+
"from notebook_utils import collect_telemetry\n",
191+
"\n",
192+
"collect_telemetry(\"grammar-correction.ipynb\")"
180193
]
181194
},
182195
{
@@ -219,25 +232,11 @@
219232
}
220233
],
221234
"source": [
222-
"import requests\n",
223-
"from pathlib import Path\n",
224-
"\n",
225-
"if not Path(\"notebook_utils.py\").exists():\n",
226-
" r = requests.get(\n",
227-
" url=\"https://raw.githubusercontent.com/openvinotoolkit/openvino_notebooks/latest/utils/notebook_utils.py\",\n",
228-
" )\n",
229-
" open(\"notebook_utils.py\", \"w\").write(r.text)\n",
230-
"\n",
231235
"from notebook_utils import device_widget\n",
232236
"\n",
233237
"device = device_widget(default=\"CPU\", exclude=[\"AUTO\", \"GPU\"])\n",
234238
"\n",
235-
"device\n",
236-
"\n",
237-
"# Read more about telemetry collection at https://github.com/openvinotoolkit/openvino_notebooks?tab=readme-ov-file#-telemetry\n",
238-
"from notebook_utils import collect_telemetry\n",
239-
"\n",
240-
"collect_telemetry(\"grammar-correction.ipynb\")"
239+
"device"
241240
]
242241
},
243242
{

notebooks/hugging-face-hub/hugging-face-hub.ipynb

+16-15
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,21 @@
9797
"import torch\n",
9898
"\n",
9999
"from transformers import AutoModelForSequenceClassification\n",
100-
"from transformers import AutoTokenizer"
100+
"from transformers import AutoTokenizer\n",
101+
"\n",
102+
"import requests\n",
103+
"\n",
104+
"if not Path(\"notebook_utils.py\").exists():\n",
105+
" r = requests.get(\n",
106+
" url=\"https://raw.githubusercontent.com/openvinotoolkit/openvino_notebooks/latest/utils/notebook_utils.py\",\n",
107+
" )\n",
108+
" open(\"notebook_utils.py\", \"w\").write(r.text)\n",
109+
"\n",
110+
"\n",
111+
"# Read more about telemetry collection at https://github.com/openvinotoolkit/openvino_notebooks?tab=readme-ov-file#-telemetry\n",
112+
"from notebook_utils import collect_telemetry\n",
113+
"\n",
114+
"collect_telemetry(\"hugging-face-hub.ipynb\")"
101115
]
102116
},
103117
{
@@ -240,24 +254,11 @@
240254
}
241255
],
242256
"source": [
243-
"import requests\n",
244-
"\n",
245-
"if not Path(\"notebook_utils.py\").exists():\n",
246-
" r = requests.get(\n",
247-
" url=\"https://raw.githubusercontent.com/openvinotoolkit/openvino_notebooks/latest/utils/notebook_utils.py\",\n",
248-
" )\n",
249-
" open(\"notebook_utils.py\", \"w\").write(r.text)\n",
250-
"\n",
251257
"from notebook_utils import device_widget\n",
252258
"\n",
253259
"device = device_widget()\n",
254260
"\n",
255-
"device\n",
256-
"\n",
257-
"# Read more about telemetry collection at https://github.com/openvinotoolkit/openvino_notebooks?tab=readme-ov-file#-telemetry\n",
258-
"from notebook_utils import collect_telemetry\n",
259-
"\n",
260-
"collect_telemetry(\"hugging-face-hub.ipynb\")"
261+
"device"
261262
]
262263
},
263264
{

notebooks/hunyuan-dit-image-generation/hunyuan-dit-image-generation.ipynb

+13-23
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,18 @@
8383
" r = requests.get(\n",
8484
" url=\"https://raw.githubusercontent.com/openvinotoolkit/openvino_notebooks/latest/utils/cmd_helper.py\",\n",
8585
" )\n",
86-
" open(\"cmd_helper.py\", \"w\").write(r.text)"
86+
" open(\"cmd_helper.py\", \"w\").write(r.text)\n",
87+
"\n",
88+
"if not Path(\"notebook_utils.py\").exists():\n",
89+
" r = requests.get(\n",
90+
" url=\"https://raw.githubusercontent.com/openvinotoolkit/openvino_notebooks/latest/utils/notebook_utils.py\",\n",
91+
" )\n",
92+
" open(\"notebook_utils.py\", \"w\").write(r.text)\n",
93+
"\n",
94+
"# Read more about telemetry collection at https://github.com/openvinotoolkit/openvino_notebooks?tab=readme-ov-file#-telemetry\n",
95+
"from notebook_utils import collect_telemetry\n",
96+
"\n",
97+
"collect_telemetry(\"hunyuan-dit-image-generation.ipynb\")"
8798
]
8899
},
89100
{
@@ -871,21 +882,11 @@
871882
}
872883
],
873884
"source": [
874-
"r = requests.get(\n",
875-
" url=\"https://raw.githubusercontent.com/openvinotoolkit/openvino_notebooks/latest/utils/notebook_utils.py\",\n",
876-
")\n",
877-
"open(\"notebook_utils.py\", \"w\").write(r.text)\n",
878-
"\n",
879885
"from notebook_utils import device_widget\n",
880886
"\n",
881887
"device = device_widget()\n",
882888
"\n",
883-
"device\n",
884-
"\n",
885-
"# Read more about telemetry collection at https://github.com/openvinotoolkit/openvino_notebooks?tab=readme-ov-file#-telemetry\n",
886-
"from notebook_utils import collect_telemetry\n",
887-
"\n",
888-
"collect_telemetry(\"hunyuan-dit-image-generation.ipynb\")"
889+
"device"
889890
]
890891
},
891892
{
@@ -1145,17 +1146,6 @@
11451146
"# demo.launch(server_name='your server name', server_port='server port in int')\n",
11461147
"# Read more in the docs: https://gradio.app/docs/"
11471148
]
1148-
},
1149-
{
1150-
"cell_type": "code",
1151-
"execution_count": null,
1152-
"id": "be7490ef",
1153-
"metadata": {},
1154-
"outputs": [],
1155-
"source": [
1156-
"# please uncomment and run this cell for stopping gradio interface\n",
1157-
"# demo.close()"
1158-
]
11591149
}
11601150
],
11611151
"metadata": {

notebooks/kosmos2-multimodal-large-language-model/kosmos2-multimodal-large-language-model.ipynb

+12-14
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,17 @@
131131
"from PIL import Image\n",
132132
"from transformers import AutoProcessor, AutoModelForVision2Seq\n",
133133
"\n",
134+
"if not Path(\"notebook_utils.py\").exists():\n",
135+
" r = requests.get(\n",
136+
" url=\"https://raw.githubusercontent.com/openvinotoolkit/openvino_notebooks/latest/utils/notebook_utils.py\",\n",
137+
" )\n",
138+
" open(\"notebook_utils.py\", \"w\").write(r.text)\n",
139+
"\n",
140+
"\n",
141+
"# Read more about telemetry collection at https://github.com/openvinotoolkit/openvino_notebooks?tab=readme-ov-file#-telemetry\n",
142+
"from notebook_utils import collect_telemetry\n",
143+
"\n",
144+
"collect_telemetry(\"kosmos2-multimodal-large-language-model.ipynb\")\n",
134145
"\n",
135146
"model = AutoModelForVision2Seq.from_pretrained(\"microsoft/kosmos-2-patch14-224\")\n",
136147
"processor = AutoProcessor.from_pretrained(\"microsoft/kosmos-2-patch14-224\")\n",
@@ -699,26 +710,13 @@
699710
}
700711
],
701712
"source": [
702-
"import requests\n",
703-
"\n",
704-
"if not Path(\"notebook_utils.py\").exists():\n",
705-
" r = requests.get(\n",
706-
" url=\"https://raw.githubusercontent.com/openvinotoolkit/openvino_notebooks/latest/utils/notebook_utils.py\",\n",
707-
" )\n",
708-
" open(\"notebook_utils.py\", \"w\").write(r.text)\n",
709-
"\n",
710713
"from notebook_utils import device_widget\n",
711714
"\n",
712715
"\n",
713716
"core = ov.Core()\n",
714717
"device = device_widget()\n",
715718
"\n",
716-
"device\n",
717-
"\n",
718-
"# Read more about telemetry collection at https://github.com/openvinotoolkit/openvino_notebooks?tab=readme-ov-file#-telemetry\n",
719-
"from notebook_utils import collect_telemetry\n",
720-
"\n",
721-
"collect_telemetry(\"kosmos2-multimodal-large-language-model.ipynb\")"
719+
"device"
722720
]
723721
},
724722
{

notebooks/magika-content-type-recognition/magika-content-type-recognition.ipynb

+15-15
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,20 @@
101101
"\n",
102102
"import openvino as ov\n",
103103
"\n",
104+
"import requests\n",
105+
"\n",
106+
"if not Path(\"notebook_utils.py\").exists():\n",
107+
" r = requests.get(\n",
108+
" url=\"https://raw.githubusercontent.com/openvinotoolkit/openvino_notebooks/latest/utils/notebook_utils.py\",\n",
109+
" )\n",
110+
" open(\"notebook_utils.py\", \"w\").write(r.text)\n",
111+
"\n",
112+
"\n",
113+
"# Read more about telemetry collection at https://github.com/openvinotoolkit/openvino_notebooks?tab=readme-ov-file#-telemetry\n",
114+
"from notebook_utils import collect_telemetry\n",
115+
"\n",
116+
"collect_telemetry(\"magika-content-type-recognition.ipynb\")\n",
117+
"\n",
104118
"\n",
105119
"class OVMagika(Magika):\n",
106120
" def __init__(\n",
@@ -267,25 +281,11 @@
267281
}
268282
],
269283
"source": [
270-
"import requests\n",
271-
"from pathlib import Path\n",
272-
"\n",
273-
"if not Path(\"notebook_utils.py\").exists():\n",
274-
" r = requests.get(\n",
275-
" url=\"https://raw.githubusercontent.com/openvinotoolkit/openvino_notebooks/latest/utils/notebook_utils.py\",\n",
276-
" )\n",
277-
" open(\"notebook_utils.py\", \"w\").write(r.text)\n",
278-
"\n",
279284
"from notebook_utils import device_widget\n",
280285
"\n",
281286
"device = device_widget()\n",
282287
"\n",
283-
"device\n",
284-
"\n",
285-
"# Read more about telemetry collection at https://github.com/openvinotoolkit/openvino_notebooks?tab=readme-ov-file#-telemetry\n",
286-
"from notebook_utils import collect_telemetry\n",
287-
"\n",
288-
"collect_telemetry(\"magika-content-type-recognition.ipynb\")"
288+
"device"
289289
]
290290
},
291291
{

0 commit comments

Comments
 (0)