Spaces:
Sleeping
Sleeping
File size: 1,337 Bytes
0e32d1b |
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 |
import os
import gradio as gr
from langchain_community.utilities.sql_database import SQLDatabase
from langchain_community.agent_toolkits import create_sql_agent
from langchain_openai import ChatOpenAI
ccms_db_loc = 'ccms.db'
ccms_db = SQLDatabase.from_uri(f"sqlite:///{ccms_db_loc}")
gpt4 = ChatOpenAI(
model_name=model_gpt4,
api_key=creds["openai_api_key"],
temperature=0
)
sqlite_agent = create_sql_agent(
gpt4,
db=ccms_db,
agent_type="openai-tools",
verbose=True
)
def predict(user_input):
try:
response = sqlite_agent.invoke(user_input)
prediction = response['output']
except Exception as e:
prediction = e
return prediction
textbox = gr.Textbox(placeholder="Enter your query here", lines=6)
demo = gr.Interface(
inputs=textbox, fn=predict, outputs="text",
title="Query Credit Card Database",
description="This web API presents an interface to ask questions on information stored in a credit card database.",
article=schema,
examples=[["Who are the top 5 merchants by total transactions?", ""],
["How many customers are in our database?", ""],
["How many accounts in total do we have?", ""]
],
concurrency_limit=8
)
demo.queue()
demo.launch(auth=("demouser", os.getenv('PASSWD'))) |