Spaces:
Runtime error
Runtime error
zachpaul38
commited on
Commit
•
00ea695
1
Parent(s):
fb98b47
Add application file
Browse files- app.py +58 -0
- requirements.txt +7 -0
app.py
ADDED
@@ -0,0 +1,58 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
|
2 |
+
# from langchain import OpenAI, SQLDatabase, SQLDatabaseChain
|
3 |
+
from langchain.agents import create_sql_agent
|
4 |
+
from langchain.agents.agent_toolkits import SQLDatabaseToolkit
|
5 |
+
from langchain.sql_database import SQLDatabase
|
6 |
+
from langchain.llms.openai import OpenAI
|
7 |
+
from langchain.agents import AgentExecutor
|
8 |
+
import openai
|
9 |
+
import json
|
10 |
+
import gradio as gr
|
11 |
+
import boto3
|
12 |
+
|
13 |
+
openai.api_key = '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'
|
14 |
+
db = SQLDatabase.from_uri("postgresql://edaiadmin:PWD4EDAIPG!@54.167.203.239:17685/bubble",schema='langchain_testing')
|
15 |
+
llm = OpenAI(temperature=0, verbose=True)
|
16 |
+
|
17 |
+
access_key = 'AKIAX7J347JABCJGWURY'
|
18 |
+
secret_key = 'LgfFSLD2Gdza2+Kw174J/5eQ3H7p1MWt2m7Zi88W'
|
19 |
+
region= 'us-east-1'
|
20 |
+
# Create S3 client
|
21 |
+
s3_client = boto3.client('s3', aws_access_key_id=access_key, aws_secret_access_key=secret_key,region_name=region)
|
22 |
+
|
23 |
+
|
24 |
+
toolkit = SQLDatabaseToolkit(db=db, llm=llm)
|
25 |
+
agent_executor = create_sql_agent(
|
26 |
+
llm=OpenAI(temperature=0),
|
27 |
+
toolkit=toolkit,
|
28 |
+
verbose=True
|
29 |
+
)
|
30 |
+
|
31 |
+
def generate_response(question):
|
32 |
+
prompt_template = """
|
33 |
+
Keep in mind that any site, building, or property related question should be routed to the real estate portal.
|
34 |
+
Any Local or city or city-sector incentives programs are asking about the local incentives program table.
|
35 |
+
Any State incentives programs are asking about the state incentives program table.
|
36 |
+
When the user asks about a state incentive, don't query the local_incentives_catalog table.
|
37 |
+
When the user asks about a local/city incentive, don't query the local_incentives_catalog table.
|
38 |
+
If you can't find the answer, make sure to look up the program field in the local and state incentives catalogs.
|
39 |
+
If your final answer is "I don't know", then respond with "Please adjust your question and try asking again."
|
40 |
+
|
41 |
+
"""
|
42 |
+
chain_response = agent_executor.run(question + prompt_template)
|
43 |
+
# bucket_name = 'your-bucket-name'
|
44 |
+
# file_name = 'flagged_text.txt'
|
45 |
+
# s3_client.put_object(Body=input_text, Bucket=bucket_name, Key=file_name)
|
46 |
+
|
47 |
+
return chain_response
|
48 |
+
|
49 |
+
iface = gr.Interface(
|
50 |
+
fn=generate_response,
|
51 |
+
inputs=gr.inputs.Textbox(label='Enter your question:', default='What is the Neighborhood Credit Fund in New York City?'),
|
52 |
+
outputs=gr.outputs.Textbox(label="EDai Analyst's Response:")
|
53 |
+
)
|
54 |
+
|
55 |
+
iface.launch(share=True)
|
56 |
+
|
57 |
+
|
58 |
+
|
requirements.txt
ADDED
@@ -0,0 +1,7 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
requests==2.27.1
|
2 |
+
pandas==1.4.2
|
3 |
+
psycopg2-binary==2.9.3
|
4 |
+
boto3==1.21.32
|
5 |
+
openai==0.27.7
|
6 |
+
langchain==0.0.184
|
7 |
+
gradio==3.32.0
|