Spaces:
Build error
Build error
Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,57 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import os
|
| 2 |
+
import gradio as gr
|
| 3 |
+
|
| 4 |
+
from langchain.agents.agent_types import AgentType
|
| 5 |
+
from langchain_experimental.agents.agent_toolkits import create_pandas_dataframe_agent
|
| 6 |
+
|
| 7 |
+
from langchain_openai import AzureChatOpenAI
|
| 8 |
+
|
| 9 |
+
from sklearn.datasets import fetch_openml
|
| 10 |
+
|
| 11 |
+
|
| 12 |
+
gpt35 = AzureChatOpenAI(
|
| 13 |
+
api_key=os.environ["AZURE_OPENAI_KEY"],
|
| 14 |
+
azure_endpoint=os.environ["AZURE_OPENAI_ENDPOINT"],
|
| 15 |
+
api_version="2023-05-15",
|
| 16 |
+
deployment_name="gpt-35-turbo"
|
| 17 |
+
)
|
| 18 |
+
|
| 19 |
+
bank_data, _ = fetch_openml(data_id=43718, return_X_y=True)
|
| 20 |
+
|
| 21 |
+
pandas_agent = create_pandas_dataframe_agent(
|
| 22 |
+
llm=gpt35,
|
| 23 |
+
df=bank_data,
|
| 24 |
+
verbose=True,
|
| 25 |
+
agent_type=AgentType.OPENAI_FUNCTIONS,
|
| 26 |
+
)
|
| 27 |
+
|
| 28 |
+
|
| 29 |
+
def predict(user_input):
|
| 30 |
+
|
| 31 |
+
try:
|
| 32 |
+
response = pandas_agent.invoke(user_input)
|
| 33 |
+
|
| 34 |
+
prediction = response['output']
|
| 35 |
+
|
| 36 |
+
except Exception as e:
|
| 37 |
+
prediction = e
|
| 38 |
+
|
| 39 |
+
return prediction
|
| 40 |
+
|
| 41 |
+
|
| 42 |
+
textbox = gr.Textbox(placeholder="Enter your query here", lines=6)
|
| 43 |
+
|
| 44 |
+
interface = gr.Interface(
|
| 45 |
+
inputs=textbox, fn=predict, outputs="text",
|
| 46 |
+
title="Query BFSI customer information",
|
| 47 |
+
description="This web API presents an interface to ask questions on customer information stored in a database.",
|
| 48 |
+
examples=[["What is the average balance maintained by the users?", ""],
|
| 49 |
+
["How many users have subscribed to a term deposit?", ""]
|
| 50 |
+
]
|
| 51 |
+
)
|
| 52 |
+
|
| 53 |
+
with gr.Blocks() as demo:
|
| 54 |
+
interface.launch()
|
| 55 |
+
|
| 56 |
+
demo.queue(concurrency_count=16)
|
| 57 |
+
demo.launch()
|