File size: 906 Bytes
308da16
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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 pandas as pd
import numpy as np
import os
from utils import *
import gradio as gr

data = pd.read_csv(os.path.join(os.getcwd(), "data_csv.csv"))

documents = create_Doc(data)

embedding = load_embedding()

vectorstore = load_vectorstore(documents=documents, embeddings=embedding)

def process(list_text, search_type = 'mmr'):
    list_text = eval(list_text)
    list_text = [title.lower() for title in list_text]
    # print(list_text)
    retrieve = vectorstore.as_retriever(search_type= search_type)
    retrieves = []
    for i in list_text:
        # print(i)
        new_suggest = retrieve.invoke(i)
        for j in new_suggest:
            if j.metadata['name'].lower() != i:
                retrieves.append(j.metadata['name'])
    return retrieves

if __name__ == "__main__":
    demo = gr.Interface(fn=process, inputs='text', outputs='text')
    demo.launch()