forked from MarkEEaton/open-journal-matcher
-
Notifications
You must be signed in to change notification settings - Fork 1
/
cloud_function.py
31 lines (28 loc) · 1.1 KB
/
cloud_function.py
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
import json
import spacy
import asyncio
from flask import Response
from aiohttp import ClientSession as Session
from gcloud.aio.storage import Storage
nlp = spacy.load("en_core_web_md", disable=["tagger", "parser", "ner"])
async def doaj_trio(request):
try:
encoded_data = request.data
string_data = encoded_data.decode()
data = json.loads(string_data)
if data["t"] == settings.token:
async with Session() as session:
storage = Storage(session=session)
bucket = storage.get_bucket(settings.bucket_name)
blob = data["f"]
print(blob)
blob_object = await bucket.get_blob(blob)
raw_data = await blob_object.download()
journal_nlp = nlp(str(raw_data)[:100000])
user_nlp = nlp(data["d"])
sim = user_nlp.similarity(journal_nlp)
return str(sim)
else:
return Response("Forbidden", status=403, mimetype="text/plain")
except:
return Response("Error", status=500, mimetype="text/plain")