File size: 3,178 Bytes
f025875 |
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 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 |
import gradio as gr
import pandas as pd
from langchain_community.vectorstores import SKLearnVectorStore
from langchain_community.embeddings import HuggingFaceBgeEmbeddings
cols = [
"Name",
"Description",
"Category",
"AI-Driven",
"Champion",
"Match score",
]
persist_path = "aecaihub.parquet"
model_name = "BAAI/bge-small-en-v1.5"
encode_kwargs = {'normalize_embeddings': True,"show_progress_bar":False,"batch_size":1} # set True to compute cosine similarity
embeddings_function = HuggingFaceBgeEmbeddings(
model_name=model_name,
encode_kwargs=encode_kwargs,
query_instruction="Represent this sentence for searching relevant passages: "
)
vector_store = SKLearnVectorStore(
embedding=embeddings_function, persist_path=persist_path, serializer="parquet"
)
def predict(query,k):
docs = vector_store.similarity_search_with_score(query,k = k)
df_results = []
for doc,score in docs:
m = doc.metadata
result_doc = {
"Name":f"**[{m['name']}]({m['url']})**",
"Description":doc.page_content,
"Category":m["category"],
"AI-Driven":m["ai_driven"],
"Champion":m["champion"],
"Match score":round(1-score,3),
}
df_results.append(result_doc)
df_results = pd.DataFrame(df_results)
return df_results
examples = [
"Tool to generate floor plans"
"AI tool for comparing building materials and sustainability",
"3D model library with image search function",
"AI-powered 3D design tool for architects and interior designers",
"Software for extracting 3D models from videos",
"AI tool for comprehensive utility data in infrastructure projects",
"AI for generating creative content in design projects",
"AI tool to convert text into architectural videos",
"AI solutions for low carbon design and data mining in architecture",
"Software for construction quantity estimation and progress tracking",
"AI interior design tool for automatic room designs"
]
# Create the Gradio interface
with gr.Blocks() as demo:
gr.Markdown("""
# 🏢 AEC AI Hub - Semantic Search Engine
This tool uses semantic search to find AI tools for Architecture Engineering and Construction (AEC) based on your question.
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/)
""")
with gr.Row():
search_bar = gr.Textbox(label="Ask you question here",scale = 2)
k = gr.Slider(minimum=1, maximum=20, value=5, label="Number of results", step=1,interactive=True)
examples = gr.Examples(
examples,search_bar, label="Examples",
)
button = gr.Button("🔍 Search")
gr.Markdown("## AI Tools")
result_df = gr.Dataframe(
headers=cols,
wrap=True,
datatype=["markdown","str","str","str","str","str"],
column_widths = ["10%","50%","10%","10%","10%","10%"],
)
(button
.click(predict, inputs = [search_bar,k], outputs=[result_df])
)
demo.launch() |