Spaces:
Runtime error
Runtime error
xiaofengalg
commited on
Commit
•
b1a85eb
1
Parent(s):
59d261f
init
Browse files- .gitjgnore +141 -0
- .vscode/settings.json +9 -0
- app.py +59 -0
.gitjgnore
ADDED
@@ -0,0 +1,141 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
.vscode
|
2 |
+
|
3 |
+
# Byte-compiled / optimized / DLL files
|
4 |
+
__pycache__/
|
5 |
+
*.py[cod]
|
6 |
+
*$py.class
|
7 |
+
|
8 |
+
# C extensions
|
9 |
+
*.so
|
10 |
+
|
11 |
+
# Distribution / packaging
|
12 |
+
.Python
|
13 |
+
build/
|
14 |
+
develop-eggs/
|
15 |
+
dist/
|
16 |
+
downloads/
|
17 |
+
eggs/
|
18 |
+
.eggs/
|
19 |
+
lib/
|
20 |
+
lib64/
|
21 |
+
parts/
|
22 |
+
sdist/
|
23 |
+
var/
|
24 |
+
wheels/
|
25 |
+
share/python-wheels/
|
26 |
+
*.egg-info/
|
27 |
+
.installed.cfg
|
28 |
+
*.egg
|
29 |
+
MANIFEST
|
30 |
+
|
31 |
+
# PyInstaller
|
32 |
+
# Usually these files are written by a python script from a template
|
33 |
+
# before PyInstaller builds the exe, so as to inject date/other infos into it.
|
34 |
+
*.manifest
|
35 |
+
*.spec
|
36 |
+
|
37 |
+
# Installer logs
|
38 |
+
pip-log.txt
|
39 |
+
pip-delete-this-directory.txt
|
40 |
+
|
41 |
+
# Unit test / coverage reports
|
42 |
+
htmlcov/
|
43 |
+
.tox/
|
44 |
+
.nox/
|
45 |
+
.coverage
|
46 |
+
.coverage.*
|
47 |
+
.cache
|
48 |
+
nosetests.xml
|
49 |
+
coverage.xml
|
50 |
+
*.cover
|
51 |
+
*.py,cover
|
52 |
+
.hypothesis/
|
53 |
+
.pytest_cache/
|
54 |
+
cover/
|
55 |
+
|
56 |
+
# Translations
|
57 |
+
*.mo
|
58 |
+
*.pot
|
59 |
+
|
60 |
+
# Django stuff:
|
61 |
+
*.log
|
62 |
+
local_settings.py
|
63 |
+
db.sqlite3
|
64 |
+
db.sqlite3-journal
|
65 |
+
|
66 |
+
# Flask stuff:
|
67 |
+
instance/
|
68 |
+
.webassets-cache
|
69 |
+
|
70 |
+
# Scrapy stuff:
|
71 |
+
.scrapy
|
72 |
+
|
73 |
+
# Sphinx documentation
|
74 |
+
docs/_build/
|
75 |
+
|
76 |
+
# PyBuilder
|
77 |
+
.pybuilder/
|
78 |
+
target/
|
79 |
+
|
80 |
+
# Jupyter Notebook
|
81 |
+
.ipynb_checkpoints
|
82 |
+
|
83 |
+
# IPython
|
84 |
+
profile_default/
|
85 |
+
ipython_config.py
|
86 |
+
|
87 |
+
# pyenv
|
88 |
+
# For a library or package, you might want to ignore these files since the code is
|
89 |
+
# intended to run in multiple environments; otherwise, check them in:
|
90 |
+
# .python-version
|
91 |
+
|
92 |
+
# pipenv
|
93 |
+
# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
|
94 |
+
# However, in case of collaboration, if having platform-specific dependencies or dependencies
|
95 |
+
# having no cross-platform support, pipenv may install dependencies that don't work, or not
|
96 |
+
# install all needed dependencies.
|
97 |
+
#Pipfile.lock
|
98 |
+
|
99 |
+
# PEP 582; used by e.g. github.com/David-OConnor/pyflow
|
100 |
+
__pypackages__/
|
101 |
+
|
102 |
+
# Celery stuff
|
103 |
+
celerybeat-schedule
|
104 |
+
celerybeat.pid
|
105 |
+
|
106 |
+
# SageMath parsed files
|
107 |
+
*.sage.py
|
108 |
+
|
109 |
+
# Environments
|
110 |
+
.env
|
111 |
+
.venv
|
112 |
+
env/
|
113 |
+
venv/
|
114 |
+
ENV/
|
115 |
+
env.bak/
|
116 |
+
venv.bak/
|
117 |
+
|
118 |
+
# Spyder project settings
|
119 |
+
.spyderproject
|
120 |
+
.spyproject
|
121 |
+
|
122 |
+
# Rope project settings
|
123 |
+
.ropeproject
|
124 |
+
|
125 |
+
# mkdocs documentation
|
126 |
+
/site
|
127 |
+
|
128 |
+
# mypy
|
129 |
+
.mypy_cache/
|
130 |
+
.dmypy.json
|
131 |
+
dmypy.json
|
132 |
+
|
133 |
+
# Pyre type checker
|
134 |
+
.pyre/
|
135 |
+
|
136 |
+
# pytype static type analyzer
|
137 |
+
.pytype/
|
138 |
+
|
139 |
+
# Cython debug symbols
|
140 |
+
cython_debug/
|
141 |
+
|
.vscode/settings.json
ADDED
@@ -0,0 +1,9 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
{
|
2 |
+
"workbench.colorCustomizations": {
|
3 |
+
"editor.lineHighlightBackground": "#1073cf2d",
|
4 |
+
"editor.lineHighlightBorder": "#9fced11f",
|
5 |
+
"activityBar.background": "#312E17",
|
6 |
+
"titleBar.activeBackground": "#454120",
|
7 |
+
"titleBar.activeForeground": "#FBFAF6"
|
8 |
+
}
|
9 |
+
}
|
app.py
ADDED
@@ -0,0 +1,59 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
# !/usr/bin/env python
|
2 |
+
# -*- coding:utf-8 -*-
|
3 |
+
# ==================================================================
|
4 |
+
# [CreatedDate] : Thursday, 1970-01-01 08:00:00
|
5 |
+
# [Author] : shixiaofeng
|
6 |
+
# [Descriptions] :
|
7 |
+
# ==================================================================
|
8 |
+
# [ChangeLog]:
|
9 |
+
# [Date] [Author] [Comments]
|
10 |
+
# ------------------------------------------------------------------
|
11 |
+
|
12 |
+
|
13 |
+
import json
|
14 |
+
import logging
|
15 |
+
import time
|
16 |
+
|
17 |
+
import gradio as gr
|
18 |
+
import requests
|
19 |
+
|
20 |
+
logger = logging.getLogger('gradio')
|
21 |
+
gr.close_all()
|
22 |
+
|
23 |
+
host = "127.0.0.1:9172"
|
24 |
+
|
25 |
+
|
26 |
+
def tableqa(input_question, history=""):
|
27 |
+
logger.info("run tableqa")
|
28 |
+
if history == "":
|
29 |
+
history_sql = None
|
30 |
+
else:
|
31 |
+
history_sql = json.loads(history.replace("\'", "\""))
|
32 |
+
data = {"raw_data": {'question': input_question, 'history_sql': history_sql}}
|
33 |
+
|
34 |
+
ts = time.time()
|
35 |
+
r = requests.post(f"http://{host}/tableqa", json=data)
|
36 |
+
response = json.loads(r.text)
|
37 |
+
print("response", response)
|
38 |
+
te = time.time()
|
39 |
+
print("run inference_mask_sam success [{}], time_Cost is [{}]".format(response["code"] == 200, te-ts))
|
40 |
+
|
41 |
+
if response["code"] == 200:
|
42 |
+
df_value = response["result"]["select_df"]
|
43 |
+
df = {"data":df_value["rows"],"headers":df_value["header_name"]}
|
44 |
+
return [df, response["result"]["sql_string"], response["result"]["sql_query"], response["result"]["history"], response["result"]["query_result"]]
|
45 |
+
else:
|
46 |
+
return ["1", "2", "3", "4",]
|
47 |
+
|
48 |
+
|
49 |
+
# iface = gr.Interface(fn=greet, inputs="text", outputs=["输出sql语句","输出可执行sql语句","执行结果"])
|
50 |
+
iface = gr.Interface(fn=tableqa, inputs=[gr.Textbox(label="input_question", info="请输入想要查询的问题."),
|
51 |
+
gr.Textbox(label="history sql", info="上下文对话历史信息.")],
|
52 |
+
outputs=[gr.DataFrame(label="索引到的数据库"),
|
53 |
+
gr.Textbox(label="输出sql语句"),
|
54 |
+
gr.Textbox(label="输出可执行sql语句"),
|
55 |
+
gr.Textbox(label="多轮对话历史sql"),
|
56 |
+
gr.Textbox(label="SQL执行结果")]
|
57 |
+
)
|
58 |
+
|
59 |
+
iface.launch(enable_queue=False, server_name="0.0.0.0", server_port=9176, debug=True)
|