import chromadb import gradio as gr import matplotlib.pyplot as plt import io from PIL import Image import re # 初始化集合 client = chromadb.PersistentClient(path="chroma_db2") output_collection = client.get_collection("data_collection") def remove1(latex_str): # 定义需要移除的命令的正则表达式 unsupported_commands = [ r'\\ref\{([^}]+)\}', # 匹配 \ref{...},保留括号内容 r'\\label\{([^}]+)\}', # 匹配 \label{...},保留括号内容 r'\\Ob\(([^)]+)\)', ] latex_str=latex_str.replace("\\\\","\\") # 逐个移除不支持的命令 for pattern in unsupported_commands: latex_str = re.sub(pattern, r'\1', latex_str) return latex_str plt.rcParams.update({ "text.usetex": True, "font.family": "serif", "axes.spines.right": False, "axes.spines.top": False, "text.latex.preamble": r"\usepackage{amsmath,amssymb}" }) def search(query,enable_latex): output_results = output_collection.get( where={"$or": [{"tag": query}, {"label": query}]}, limit=1 ) if not output_results["ids"]: return ["No matching results found",None,''] # 获取匹配的output信息 tag= output_results["metadatas"][0]["tag"] label= output_results["metadatas"][0]["label"] latex= output_results["documents"][0] latex_output = f"""
✍ Tag: {tag}
💬 Label: {label}
⭐ LaTeX: {latex}
📜 Formal Statement:
{fs}
⭐ Kind: {kind}
✍ Informal Name: {inn}
💬 Informal Statement: {ins}
✌ Similarity Ranking: {l+1}