File size: 1,472 Bytes
0e32d1b
 
 
 
 
 
 
 
 
 
 
 
 
6db70a4
60b263a
0e32d1b
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
8c8a80e
0e32d1b
 
 
cc356ac
0e32d1b
cc356ac
 
 
 
 
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
56
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='gpt-4',
    api_key=os.environ["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)
schema = <img src="https://cdn-uploads.huggingface.co/production/uploads/64118e60756b9e455c7eddd6/81ggHEjrt6wFrMyXJtHVS.png" >

demo = gr.Interface(
    inputs=textbox, fn=predict, outputs="text",
    title="Query a 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')))