File size: 4,941 Bytes
c7e0b67
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {},
   "outputs": [],
   "source": [
    "from langchain.document_loaders import ImageCaptionLoader"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {},
   "outputs": [],
   "source": [
    "list_image_urls = [\n",
    "    'https://t7.baidu.com/it/u=2168645659,3174029352&fm=193&f=GIF',\n",
    "    'https://t7.baidu.com/it/u=2851687453,2321283050&fm=193&f=GIF',\n",
    "    'https://t7.baidu.com/it/u=3601447414,1764260638&fm=193&f=GIF',\n",
    "    'https://gimg2.baidu.com/image_search/src=http%3A%2F%2Fc-ssl.duitang.com%2Fuploads%2Fblog%2F202111%2F17%2F20211117092914_579a7.thumb.1000_0.jpeg&refer=http%3A%2F%2Fc-ssl.duitang.com&app=2002&size=f9999,10000&q=a80&n=0&g=0n&fmt=auto?sec=1685104926&t=62afde36bb3200aa727ced1c8fb18eab',\n",
    "    'https://img1.baidu.com/it/u=219752959,2207818343&fm=253&fmt=auto&app=138&f=JPEG?w=500&h=725',\n",
    "    'https://img2.baidu.com/it/u=3813658383,1119780612&fm=253&fmt=auto&app=120&f=JPEG?w=1280&h=800',\n",
    "]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {},
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "/Users/tutu/anaconda3/lib/python3.10/site-packages/transformers/generation/utils.py:1313: UserWarning: Using `max_length`'s default (20) to control the generation length. This behaviour is deprecated and will be removed from the config in v5 of Transformers -- we recommend using `max_new_tokens` to control the maximum length of the generation.\n",
      "  warnings.warn(\n"
     ]
    },
    {
     "data": {
      "text/plain": [
       "[Document(page_content='an image of two women in kimono [SEP]', metadata={'image_path': 'https://t7.baidu.com/it/u=2168645659,3174029352&fm=193&f=GIF'}),\n",
       " Document(page_content='an image of a cat eating fish [SEP]', metadata={'image_path': 'https://t7.baidu.com/it/u=2851687453,2321283050&fm=193&f=GIF'}),\n",
       " Document(page_content='an image of a cat and dog [SEP]', metadata={'image_path': 'https://t7.baidu.com/it/u=3601447414,1764260638&fm=193&f=GIF'}),\n",
       " Document(page_content='an image of a girl in a school uniform [SEP]', metadata={'image_path': 'https://gimg2.baidu.com/image_search/src=http%3A%2F%2Fc-ssl.duitang.com%2Fuploads%2Fblog%2F202111%2F17%2F20211117092914_579a7.thumb.1000_0.jpeg&refer=http%3A%2F%2Fc-ssl.duitang.com&app=2002&size=f9999,10000&q=a80&n=0&g=0n&fmt=auto?sec=1685104926&t=62afde36bb3200aa727ced1c8fb18eab'}),\n",
       " Document(page_content='an image of a woman in a blue sweater [SEP]', metadata={'image_path': 'https://img1.baidu.com/it/u=219752959,2207818343&fm=253&fmt=auto&app=138&f=JPEG?w=500&h=725'}),\n",
       " Document(page_content='an image of a woman in a yellow dress [SEP]', metadata={'image_path': 'https://img2.baidu.com/it/u=3813658383,1119780612&fm=253&fmt=auto&app=120&f=JPEG?w=1280&h=800'})]"
      ]
     },
     "execution_count": 9,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "loader = ImageCaptionLoader(path_images=list_image_urls)\n",
    "list_docs = loader.load()\n",
    "list_docs"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {},
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "Using embedded DuckDB without persistence: data will be transient\n"
     ]
    }
   ],
   "source": [
    "from langchain.indexes import VectorstoreIndexCreator\n",
    "index = VectorstoreIndexCreator().from_loaders([loader])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 30,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "' ζˆ‘δΈηŸ₯道。'"
      ]
     },
     "execution_count": 30,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "query = \"η”¨δΈ­ζ–‡ε›žη­”οΌŒη‹—ζ˜―δ»€δΉˆε“η§\"\n",
    "index.query(query)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "' There are images of a cat and dog, a cat eating fish, two women in kimono, and a woman in a blue sweater.'"
      ]
     },
     "execution_count": 12,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "query = \"What kind of images are there?\"\n",
    "index.query(query)"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "base",
   "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.10.10"
  },
  "orig_nbformat": 4
 },
 "nbformat": 4,
 "nbformat_minor": 2
}