مستند بسيط ومحرك بحث صور يتم تنفيذه في Keras
GOTO KERAS_SEARCH_ENGINE_WEB دليل وتشغيل الأمر التالي:
python flaskr.pyالآن انتقل متصفحك إلى http: // localhost: 5000 ويمكنك تجربة الخروج
مع تشغيل خادم API على الويب ، يمكنك فهرسة مستند جديد عن طريق استدعاء واجهة برمجة تطبيقات الويب التالية:
http://localhost:5000/index_textعلى سبيل المثال ، ما يلي هو أمر Curl للاتصال بأجهزة واجهة برمجة تطبيقات الويب لفهرسة بعض المستندات:
curl -H ' Content-Type application/json ' -X POST -d ' {"doc":"Whether you think that you can, or that you can ' t, you are usually right. " }' http://localhost:5000/index_text
curl -H 'Content-Type application/json' -X POST -d '{ " doc " : " Try to learn something about everything and everything about something. " }' http://localhost:5000/index_text
curl -H 'Content-Type application/json' -X POST -d '{ " doc " : " You can avoid reality, but you cannot avoid the consequences of avoiding reality. " }' http://localhost:5000/index_text
curl -H 'Content-Type application/json' -X POST -d '{ " doc " : " A mathematician is a device for turning coffee into theorems. " }' http://localhost:5000/index_text
curl -H 'Content-Type application/json' -X POST -d '{ " doc " : " In theory, there is no difference between theory and practice. But in practice, there is. " }' http://localhost:5000/index_text
curl -H 'Content-Type application/json' -X POST -d '{ " doc " : " I find that the harder I work, the more luck I seem to have. " }' http://localhost:5000/index_textللاستعلام باستخدام واجهة برمجة تطبيقات الويب ، يمكنك الاتصال بأجهزة واجهة برمجة تطبيقات الويب التالية:
curl -H ' Content-Type application/json ' -X POST -d ' {"query":"mathematician and coffee", "limit": 3, "model": "glove"} ' http://localhost:5000/search_textمع تشغيل خادم API على الويب ، يمكنك فهرسة صورة جديدة عن طريق الاتصال بأجهزة واجهة برمجة تطبيقات الويب التالية عبر طلب النشر:
http://localhost:5000/index_imageيمكنك الاستعلام عن صور مماثلة عن طريق الاتصال بطلب نشر API التالي:
http://localhost:5000/search_image/10حيث 10 هو الحد من عدد الصور التي تم إرجاعها
هناك أيضًا فئة SearchenGineclient في Keras_Search_Engine_Client ، تبدو رموز العينة مثل:
from keras_search_engine_client . search_engine_client import SearchEngineClient
client = SearchEngineClient ()
# text indexing and search
doc_count = client . doc_count ()
if doc_count < 4 :
client . index_text ( 'Whether you think that you can, or that you can.' )
client . index_text ( 'Try to learn something about everything and everything about something.' )
client . index_text ( 'You can avoid reality, but you cannot avoid the consequences of avoiding reality.' )
client . index_text ( 'A mathematician is a device for turning coffee into theorems.' )
client . index_text ( 'In theory, there is no difference between theory and practice. But in practice, there is.' )
client . index_text ( 'I find that the harder I work, the more luck I seem to have.' )
client . search_text ( query = 'mathematician and coffee' , limit = 3 , model = 'glove' )
client . search_text ( query = 'mathematician and coffee' , limit = 3 , model = 'doc-encoder' )
# image indexing and search
client . index_image ( './images/Pokemon7.png' )
client . search_image ( './images/Pokemon1.jpg' , 6 )