File size: 949 Bytes
e468f5a a46f28b eaee63c e468f5a a46f28b eaee63c a46f28b 40e2a74 eaee63c 4183fb4 a46f28b 1e95982 eaee63c 40e2a74 |
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 |
# -*- coding: utf-8 -*-
"""
Created on Wed Mar 22 19:59:54 2023
"""
import gradio as gr
from simiandb import Simiandb
from langchain.embeddings import HuggingFaceEmbeddings
from sentence_transformers import CrossEncoder
model_name = "all-MiniLM-L6-v2"
hf = HuggingFaceEmbeddings(model_name=model_name)
cross_encoder = CrossEncoder('cross-encoder/ms-marco-MiniLM-L-6-v2')
documentdb = Simiandb("mystore", embedding_function=hf, mode="a")
def search(query):
hits = documentdb.similarity_search(query, k=10)
cross_inp = [[query, hit] for hit in hits]
cross_scores = cross_encoder.predict(cross_inp)
hits = [hit for _, hit in sorted(zip(cross_scores, hits), reverse=True)]
return hits[0]
iface = gr.Interface(fn=search, inputs=gr.Textbox(lines=2, placeholder="Write a question to the Wikipedia..."), outputs="text")
iface.launch()
#print(search("what is the balloon boy hoax"))
# print(search("date of birth of elon musk")) |