Spaces:
Sleeping
Sleeping
test
Browse files
app.py
CHANGED
|
@@ -40,7 +40,7 @@ raw_jsons = json.loads(decrypted_content)
|
|
| 40 |
docs = []
|
| 41 |
metas = []
|
| 42 |
|
| 43 |
-
for vhjx_item in raw_jsons
|
| 44 |
chapter = vhjx_item[0]
|
| 45 |
for jvvi_item in vhjx_item[1:]:
|
| 46 |
content = jvvi_item["原文"]
|
|
@@ -52,28 +52,29 @@ for vhjx_item in raw_jsons[:1]:
|
|
| 52 |
"critique": jvvi_item.get("批判", ""),
|
| 53 |
"chapter": chapter
|
| 54 |
})
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 55 |
|
| 56 |
-
#
|
| 57 |
-
|
| 58 |
-
|
| 59 |
-
|
| 60 |
-
|
| 61 |
-
|
| 62 |
-
|
| 63 |
-
|
| 64 |
-
|
| 65 |
-
|
| 66 |
-
|
| 67 |
-
|
| 68 |
-
|
| 69 |
-
"annotation": item["annotation"],
|
| 70 |
-
"critique": item["critique"],
|
| 71 |
-
"chapter": item["chapter"]
|
| 72 |
-
})
|
| 73 |
|
| 74 |
-
# 插入数据
|
| 75 |
-
client.insert(collection_name="collection_1", data=milvus_data)
|
| 76 |
-
print(f"✅ 插入完成:共 {len(milvus_data)} 条数据")
|
| 77 |
|
| 78 |
def greet(name):
|
| 79 |
embeddings = llm.create_embedding(name)
|
|
@@ -83,8 +84,7 @@ def greet(name):
|
|
| 83 |
limit=2,
|
| 84 |
output_fields=["text", "id"],
|
| 85 |
)
|
| 86 |
-
|
| 87 |
-
return "Hello " + name + "!!"
|
| 88 |
|
| 89 |
-
demo = gr.Interface(fn=greet, inputs="text", outputs="
|
| 90 |
demo.launch(mcp_server=True)
|
|
|
|
| 40 |
docs = []
|
| 41 |
metas = []
|
| 42 |
|
| 43 |
+
for vhjx_index, vhjx_item in enumerate(raw_jsons):
|
| 44 |
chapter = vhjx_item[0]
|
| 45 |
for jvvi_item in vhjx_item[1:]:
|
| 46 |
content = jvvi_item["原文"]
|
|
|
|
| 52 |
"critique": jvvi_item.get("批判", ""),
|
| 53 |
"chapter": chapter
|
| 54 |
})
|
| 55 |
+
|
| 56 |
+
# 一个章节一次
|
| 57 |
+
# 批量生成 embeddings(每个为 list[float])
|
| 58 |
+
emb_result = llm.create_embedding(docs)
|
| 59 |
+
embeddings = [item["embedding"] for item in emb_result["data"]] # List[List[float]]
|
| 60 |
|
| 61 |
+
# 准备数据
|
| 62 |
+
milvus_data = []
|
| 63 |
+
for i, emb in enumerate(embeddings):
|
| 64 |
+
item = metas[i]
|
| 65 |
+
milvus_data.append({
|
| 66 |
+
"id" : vhjx_index * 100 + i,
|
| 67 |
+
"index": item["index"],
|
| 68 |
+
"vector": emb,
|
| 69 |
+
"text": item["text"],
|
| 70 |
+
"annotation": item["annotation"],
|
| 71 |
+
"critique": item["critique"],
|
| 72 |
+
"chapter": item["chapter"]
|
| 73 |
+
})
|
|
|
|
|
|
|
|
|
|
|
|
|
| 74 |
|
| 75 |
+
# 插入数据
|
| 76 |
+
client.insert(collection_name="collection_1", data=milvus_data)
|
| 77 |
+
print(f"✅ 插入完成:共 {len(milvus_data)} 条数据")
|
| 78 |
|
| 79 |
def greet(name):
|
| 80 |
embeddings = llm.create_embedding(name)
|
|
|
|
| 84 |
limit=2,
|
| 85 |
output_fields=["text", "id"],
|
| 86 |
)
|
| 87 |
+
return res
|
|
|
|
| 88 |
|
| 89 |
+
demo = gr.Interface(fn=greet, inputs="text", outputs=gr.JSON(label="查询结果"))
|
| 90 |
demo.launch(mcp_server=True)
|