Spaces:
Sleeping
Sleeping
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'))) |