Update app.py
Browse files
app.py
CHANGED
@@ -1,72 +1,72 @@
|
|
1 |
-
|
2 |
-
|
3 |
-
|
4 |
-
|
5 |
-
|
6 |
-
|
7 |
-
|
8 |
-
|
9 |
-
|
10 |
-
|
11 |
-
|
12 |
-
|
13 |
-
|
14 |
-
|
15 |
-
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
|
22 |
-
|
23 |
|
24 |
-
logging.basicConfig(format="%(levelname)s - %(name)s -
|
25 |
-
logging.getLogger(
|
26 |
|
27 |
-
|
28 |
|
29 |
-
f = codecs.open('faq.txt','r','UTF-8')
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
-
|
34 |
|
35 |
-
|
36 |
-
|
37 |
|
38 |
-
|
39 |
-
lines.append([line[i],line[i+1]])
|
40 |
|
41 |
-
colu = ['
|
42 |
|
43 |
-
df = pd.DataFrame
|
44 |
-
|
45 |
-
|
46 |
-
embedding_model="
|
47 |
-
use_gpu
|
48 |
-
scale_score
|
49 |
)
|
50 |
-
question = list(df['question'].values)
|
51 |
|
52 |
-
df['embedding'] = retriever.embed_queries(queries=question).tolist()
|
53 |
-
df = df.rename(columns={'question': 'content'})
|
54 |
-
question = list(df['question'].values)
|
55 |
-
docs_to_index = df.to_dict(orient='records')
|
56 |
-
document_store.write_documents(docs_to_index)
|
57 |
|
|
|
|
|
|
|
|
|
|
|
58 |
|
59 |
-
def haysstack(input,retriever=retriever):
|
60 |
-
pipe = FAQPipeline(retriever=retriever)
|
61 |
-
prediction = pipe.run(query=input, params={"Retriever": {"top_k": 1}})
|
62 |
-
return prediction['answers']
|
63 |
-
# Run any question and change top_k to see more or less answers
|
64 |
|
65 |
-
|
66 |
-
|
67 |
-
|
68 |
-
|
|
|
69 |
|
70 |
-
gr
|
71 |
-
|
72 |
-
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
从haystack.telemetry导入tutorial_running
|
2 |
+
导入日志
|
3 |
+
从haystack.document_stores导入InMemoryDocumentStore
|
4 |
+
从haystack.pipelines.standard_pipelines导入TextIndexingPipeline
|
5 |
+
从haystack.nodes导入BM25Retriever
|
6 |
+
从haystack.nodes导入FARMReader
|
7 |
+
从haystack.pipelines导入ExtractiveQAPipeline
|
8 |
+
从pprint导入pprint
|
9 |
+
从haystack.utils导入print_answers
|
10 |
+
从 haystack.nodes 导入 EmbeddingRetriever
|
11 |
+
导入解码器
|
12 |
+
从 haystack.pipelines 导入 FAQPipeline
|
13 |
+
从 haystack.utils 导入 print_answers
|
14 |
+
导入日志
|
15 |
+
从 haystack.telemetry 导入tutorial_running
|
16 |
+
从 haystack.document_stores 导入 InMemoryDocumentStore
|
17 |
+
从 haystack.nodes 导入 EmbeddingRetriever
|
18 |
+
将熊猫导入为pd
|
19 |
+
从 haystack.pipelines 导入 FAQPipeline
|
20 |
+
从 haystack.utils 导入 print_answers
|
21 |
|
22 |
+
教程_运行(6)
|
23 |
|
24 |
+
logging.basicConfig(format= "%(levelname)s - %(name)s - %(message)s" , level=logging.WARNING)
|
25 |
+
logging.getLogger( “干草堆” ).setLevel(logging.INFO)
|
26 |
|
27 |
+
文档存储器 = InMemoryDocumentStore()
|
28 |
|
29 |
+
f = codecs.open( 'faq.txt' , 'r' , 'UTF-8' )
|
30 |
+
行 = f.readlines()
|
31 |
+
行 = []
|
32 |
+
对于范围内的 i ( 2 , 33 , 2 ):
|
33 |
+
行.pop(i)
|
34 |
|
35 |
+
对于我在范围内(33):
|
36 |
+
行[i] = 行[i][:- 2 ]
|
37 |
|
38 |
+
对于我在范围内(0、33、2): _
|
39 |
+
lines.append([line[i],line[i+ 1 ]])
|
40 |
|
41 |
+
colu = [ '问题' , '答案' ]
|
42 |
|
43 |
+
df = pd.DataFrame(数据=行,列=列)
|
44 |
+
检测器 = EmbeddingRetriever(
|
45 |
+
文档存储器=文档存储器,
|
46 |
+
embedding_model= "句子变换器/all-MiniLM-L6-v2" ,
|
47 |
+
use_gpu=真,
|
48 |
+
scale_score=假,
|
49 |
)
|
|
|
50 |
|
|
|
|
|
|
|
|
|
|
|
51 |
|
52 |
+
df[ '嵌入'] = retriever.embed_queries(查询=问题).tolist()
|
53 |
+
df = df.rename(columns={ 'question' : 'content' })
|
54 |
+
问题 = 列表(df[ '问题' ].values)
|
55 |
+
docs_to_index = df.to_dict(orient= '记录' )
|
56 |
+
document_store.write_documents(docs_to_index)
|
57 |
|
|
|
|
|
|
|
|
|
|
|
58 |
|
59 |
+
定义haysstack(输入,检查器=检查器):
|
60 |
+
pipe = FAQPipeline(检测器=检测器)
|
61 |
+
prediction = pipe.run(query=input, params={ "Retriever" : { "top_k" : 1 }})
|
62 |
+
返回预测
|
63 |
+
# 运行任何问题并更改 top_k 以查看更多或更少的答案
|
64 |
|
65 |
+
将易变导入为gr
|
66 |
+
从gradio.components导入文档
|
67 |
+
inputs = Textbox(lines= 7 , label= "请输入你的问题" )
|
68 |
+
outputs = Textbox(lines= 7 , label= "来自ChatGPT的回答" )
|
69 |
+
|
70 |
+
gr.Interface(fn=haysstack, inputs=inputs, outputs=outputs, title= "电商客服" ,
|
71 |
+
description= "我是您的电商客服,您可以问任何您想知道的问题" ,
|
72 |
+
主题=gr.themes.Default()).launch(share= True )
|