-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathStart.py
More file actions
138 lines (118 loc) · 5.18 KB
/
Copy pathStart.py
File metadata and controls
138 lines (118 loc) · 5.18 KB
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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
from elasticsearch import Elasticsearch
from openai import OpenAI
from pywebio.input import *
from pywebio.output import *
from pywebio.session import *
from pywebio import start_server
import json
import UI
import Config
import Check
import Initialize
import Search
import Transform
def main():
UI.MainUI()
actions(buttons=[{'label': '🚀 开始', 'value': 0}])
clear()
if not Config.CheckFirst():
toast("⚡ 开始初始化配置文件...")
config = Config.SetConfig()
else:
config = Config.GetConfig()
es = Elasticsearch(config['ESURL'])
index_name = config['INDEX']
client = OpenAI(api_key=config['KEY'], base_url=config['BASE'])
path = config['PATH']
while True:
if Check.CheckES(es) and Check.CheckOpenAi(client):
break
act = actions("", [{'label': '重新配置', 'color': 'warning','value':1}, {'label': '重试', 'value':0}])
match act:
case 0:
continue
case 1:
config = Config.SetConfig()
es = Elasticsearch(config['ESURL'])
index_name = config['INDEX']
client = OpenAI(api_key=config['KEY'], base_url=config['BASE'])
path = config['PATH']
if not es.indices.exists(index=index_name):
Initialize.Initialize(es, index_name)
with open('config/index.json', 'r', encoding='utf-8') as f:
index_config = json.load(f)
if index_config[-1]['style'] == 'default':
head = ["ID", "品牌", "比例", "赛季", "车队", "型号", "车手", "车号", "分站", "名次", "状态", "入库时间", "购入价格", "卖出价格", "备注"]
keyword = ["品牌", "比例", "赛季", "车队", "型号", "车手", "车号", "分站", "名次", "状态", "备注"]
text = ["备注", "描述"]
number = ["入库时间", "购入价格", "卖出价格"]
style = 'default'
else:
head = ["ID",]
keyword = []
text = []
number = []
for field in index_config[1:-1]:
head.append(field['name'])
if field['type'] == 'text':
keyword.append(field['name'])
text.append(field['name'])
elif field['type'] == 'keyword':
keyword.append(field['name'])
elif field['type'] == 'integer':
number.append(field['name'])
style = 'custom'
head.append('操作')
while True:
UI.MainUI()
menu = actions(buttons=[{'label': '📋 批量查找', 'value': 1}, {'label': '🔍 关键词检索', 'value': 2}, {'label': '✨ 模糊检索', 'value': 3},
{'label': '🤖 语义检索', 'value': 4}, {'label': '➕ 新增条目', 'value': 5}, {'label': '📥 导入数据', 'value': 6},
{'label': '📤 导出数据', 'value': 7}, {'label': '⚙️ 设置参数', 'value': 8},
{'label': '🚪 退出系统', 'value': 0, 'color': 'warning'}])
match menu:
case 0:
clear()
return
case 1:
clear()
Search.BatchSearch(es, index_name, head, text, number, client, style)
case 2:
clear()
Search.KeywordSearch(es, index_name, head, text, number, client, style, keyword)
case 3:
clear()
Search.FuzzySearch(es, index_name, head, text, number, client, style)
case 4:
clear()
Search.SemanticSearch(es, index_name, head, text, number, client, style)
case 5:
clear()
Transform.InputOne(es, index_name, head, text, number, client, style)
case 6:
clear()
Transform.InputData(es, index_name, head, text, client, style)
case 7:
clear()
Transform.OutputData(es, index_name, head, style, path)
case 8:
clear()
config = Config.SetConfig()
es = Elasticsearch(config['ESURL'])
index_name = config['INDEX']
client = OpenAI(api_key=config['KEY'], base_url=config['BASE'])
path = config['PATH']
while True:
if Check.CheckES(es) and Check.CheckOpenAi(client):
break
act = actions("", [{'label': '重新配置', 'color': 'warning','value':1}, {'label': '重试', 'value':0}])
match act:
case 0:
continue
case 1:
config = Config.SetConfig()
es = Elasticsearch(config['ESURL'])
index_name = config['INDEX']
client = OpenAI(api_key=config['KEY'], base_url=config['BASE'])
path = config['PATH']
if __name__ == '__main__':
main()