CoolFace
Apppublic

TheoLvs/aec-tools

sourceHugging Facemitupdated 3y agoView on Hugging Face
0likes
app.py92 linesDownload Raw Back to root
1import gradio as gr2import pandas as pd3from langchain_community.vectorstores import SKLearnVectorStore4from langchain_community.embeddings import HuggingFaceBgeEmbeddings5 6cols = [7    "Name",8    "Description",9    "Category",10    "AI-Driven",11    "Champion",12    "Match score",13]14 15persist_path = "aecaihub.parquet"16 17model_name = "BAAI/bge-small-en-v1.5"18encode_kwargs = {'normalize_embeddings': True,"show_progress_bar":False,"batch_size":1} # set True to compute cosine similarity19embeddings_function = HuggingFaceBgeEmbeddings(20    model_name=model_name,21    encode_kwargs=encode_kwargs,22    query_instruction="Represent this sentence for searching relevant passages: "23)24 25 26vector_store = SKLearnVectorStore(27    embedding=embeddings_function, persist_path=persist_path, serializer="parquet"28)29 30def predict(query,k):31 32    docs = vector_store.similarity_search_with_score(query,k = k)33 34    df_results = []35    for doc,score in docs:36        m = doc.metadata37        result_doc = {38            "Name":f"**[{m['name']}]({m['url']})**",39            "Description":doc.page_content,40            "Category":m["category"],41            "AI-Driven":m["ai_driven"],42            "Champion":m["champion"],43            "Match score":round(1-score,3),44        }45        46        df_results.append(result_doc)47    df_results = pd.DataFrame(df_results)48    return df_results49 50 51examples = [52    "Tool to generate floor plans"53    "AI tool for comparing building materials and sustainability",54    "3D model library with image search function",55    "AI-powered 3D design tool for architects and interior designers",56    "Software for extracting 3D models from videos",57    "AI tool for comprehensive utility data in infrastructure projects",58    "AI for generating creative content in design projects",59    "AI tool to convert text into architectural videos",60    "AI solutions for low carbon design and data mining in architecture",61    "Software for construction quantity estimation and progress tracking",62    "AI interior design tool for automatic room designs"63]64 65# Create the Gradio interface66with gr.Blocks() as demo:67    gr.Markdown("""68        # ๐Ÿข AEC AI Hub - Semantic Search Engine69        This tool uses semantic search to find AI tools for Architecture Engineering and Construction (AEC) based on your question.70        The database is drawn from the [great work](https://stjepanmikulic.notion.site/AEC-AI-Hub-b6e6eebe88094e0e9b4995da38e96768) of [Stjepan Mikulic](https://www.linkedin.com/in/stjepanmikulic/)71    """)72 73    with gr.Row():74        search_bar = gr.Textbox(label="Ask you question here",scale = 2)75        k = gr.Slider(minimum=1, maximum=20, value=5, label="Number of results", step=1,interactive=True)76    examples = gr.Examples(77            examples,search_bar, label="Examples",78    )79    button = gr.Button("๐Ÿ” Search")80    gr.Markdown("## AI Tools")81    result_df = gr.Dataframe(82        headers=cols,83        wrap=True,84        datatype=["markdown","str","str","str","str","str"],85        column_widths = ["10%","50%","10%","10%","10%","10%"],86    )87 88    (button89        .click(predict, inputs = [search_bar,k], outputs=[result_df])90    )91 92demo.launch()