Spaces:
Runtime error
Runtime error
# !/usr/bin/env python | |
# -*- coding:utf-8 -*- | |
# ================================================================== | |
# [CreatedDate] : Thursday, 1970-01-01 08:00:00 | |
# [Author] : shixiaofeng | |
# [Descriptions] : | |
# ================================================================== | |
# [ChangeLog]: | |
# [Date] [Author] [Comments] | |
# ------------------------------------------------------------------ | |
import json | |
import logging | |
import time | |
import gradio as gr | |
import requests | |
logger = logging.getLogger('gradio') | |
gr.close_all() | |
host = "127.0.0.1:9172" | |
def tableqa(input_question, history=""): | |
logger.info("run tableqa") | |
if history == "": | |
history_sql = None | |
else: | |
history_sql = json.loads(history.replace("\'", "\"")) | |
data = {"raw_data": {'question': input_question, 'history_sql': history_sql}} | |
ts = time.time() | |
r = requests.post(f"http://{host}/tableqa", json=data) | |
response = json.loads(r.text) | |
print("response", response) | |
te = time.time() | |
print("run inference_mask_sam success [{}], time_Cost is [{}]".format(response["code"] == 200, te-ts)) | |
if response["code"] == 200: | |
df_value = response["result"]["select_df"] | |
df = {"data":df_value["rows"],"headers":df_value["header_name"]} | |
return [df, response["result"]["sql_string"], response["result"]["sql_query"], response["result"]["history"], response["result"]["query_result"]] | |
else: | |
return ["1", "2", "3", "4",] | |
# iface = gr.Interface(fn=greet, inputs="text", outputs=["输出sql语句","输出可执行sql语句","执行结果"]) | |
iface = gr.Interface(fn=tableqa, inputs=[gr.Textbox(label="input_question", info="请输入想要查询的问题."), | |
gr.Textbox(label="history sql", info="上下文对话历史信息.")], | |
outputs=[gr.DataFrame(label="索引到的数据库"), | |
gr.Textbox(label="输出sql语句"), | |
gr.Textbox(label="输出可执行sql语句"), | |
gr.Textbox(label="多轮对话历史sql"), | |
gr.Textbox(label="SQL执行结果")] | |
) | |
iface.launch(enable_queue=False, server_name="0.0.0.0", server_port=9176, debug=True) | |