Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -20,8 +20,13 @@ sim_model.add_corpus(load_file('corpus.txt'))
|
|
| 20 |
|
| 21 |
def ai_text(query):
|
| 22 |
res = sim_model.most_similar(queries=query, topn=5)
|
| 23 |
-
|
| 24 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 25 |
return res_show
|
| 26 |
|
| 27 |
|
|
@@ -32,12 +37,12 @@ if __name__ == '__main__':
|
|
| 32 |
['她在看书'],
|
| 33 |
['一个人弹琴'],
|
| 34 |
]
|
| 35 |
-
|
| 36 |
-
|
| 37 |
-
|
| 38 |
-
|
| 39 |
-
|
| 40 |
-
|
| 41 |
-
|
| 42 |
-
|
| 43 |
-
|
|
|
|
| 20 |
|
| 21 |
def ai_text(query):
|
| 22 |
res = sim_model.most_similar(queries=query, topn=5)
|
| 23 |
+
print(res)
|
| 24 |
+
for q_id, c in enumerate(res):
|
| 25 |
+
print('query:', query)
|
| 26 |
+
print("search top 5:")
|
| 27 |
+
print(f'\t{c}')
|
| 28 |
+
res_show = '\n'.join(
|
| 29 |
+
['search top5:'] + [f'text: {k.get("corpus_doc")} score: {k.get("score"):.4f}' for k in res[0]])
|
| 30 |
return res_show
|
| 31 |
|
| 32 |
|
|
|
|
| 37 |
['她在看书'],
|
| 38 |
['一个人弹琴'],
|
| 39 |
]
|
| 40 |
+
gr.Interface(
|
| 41 |
+
ai_text,
|
| 42 |
+
inputs=gr.Textbox(lines=2, label="Enter Query"),
|
| 43 |
+
outputs=gr.Textbox(label="Output Box"),
|
| 44 |
+
title="Chinese Text Semantic Search Model",
|
| 45 |
+
description="Copy or input Chinese text here. Submit and the machine will find the most similarity texts.",
|
| 46 |
+
article="Link to <a href='https://github.com/shibing624/similarities' style='color:blue;' target='_blank'>Github REPO</a>",
|
| 47 |
+
examples=examples
|
| 48 |
+
).launch()
|