Skip to content

Commit 953b4ad

Browse files
committed
simple img show added
1 parent 2e5a810 commit 953b4ad

File tree

5 files changed

+23
-13
lines changed

5 files changed

+23
-13
lines changed

requirements.txt

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
nltk
2-
gensim
3-
zstd
2+
zstd
3+
pillow
4+
requests

semantic_search.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
from bool_search import Bool_Search
55
from utils.data_process import Data
66
from utils.tf_idf import TF_IDF
7+
from utils.img import show_image
78
import logging
89

910

@@ -106,5 +107,11 @@ def load():
106107
else:
107108
for docid in range(len(res)):
108109
if(res[docid][0] > 0):
109-
print('{}:\t{}'.format(res[docid][0],
110-
metadata[res[docid][1]]['title']))
110+
imgurl = metadata[res[docid][1]]['img']
111+
title = metadata[res[docid][1]]['title']
112+
print('{}:\t{}'.format(res[docid][0],title),end='\t')
113+
if len(imgurl) > 0:
114+
print('Found image')
115+
show_image(imgurl,title)
116+
else:
117+
print('Image not found')

utils/data_process.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,9 +52,10 @@ def load(self, path="./data", maxfile=-1):
5252
self.metadata.append({
5353
"id": rawdata["uuid"],
5454
# "time": rawdata["published"],
55-
"title": rawdata["title"]
55+
"title": rawdata["title"],
5656
# "author": rawdata["author"],
5757
# "url": rawdata["url"]
58+
"img": rawdata["thread"]["main_image"]
5859
})
5960
if file_id == maxfile:
6061
logging.info(f'Maxfile reached, {file_id} file loaded')
@@ -154,4 +155,4 @@ def process(self):
154155
self.strip_stop_words(
155156
self.pre_process(self.headerdata[docid])))
156157
self.parse_syn()
157-
self.gen_dict()
158+
self.gen_dict()

utils/img.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
from requests import get
2+
from PIL import Image
3+
from io import BytesIO
4+
5+
def show_image(url,title):
6+
raw = get(url)
7+
img = Image.open(BytesIO(raw.content))
8+
img.show(title=title)

utils/word2vec.py

Lines changed: 0 additions & 7 deletions
This file was deleted.

0 commit comments

Comments
 (0)