Spaces:
Sleeping
Sleeping
Add query op and alarm table
Browse files
app.py
CHANGED
@@ -96,7 +96,7 @@ def main():
|
|
96 |
path = r"OPPI_shift.db" # \OPPI_down.db"
|
97 |
db1 = SQLDatabase.from_uri(f"sqlite:///{path}", include_tables=['ShiftDownTimeDetails'],sample_rows_in_table_info=0)
|
98 |
db2 = SQLDatabase.from_uri(f"sqlite:///{path}", include_tables=['ShiftProductionDetails'],sample_rows_in_table_info=0)
|
99 |
-
db3 = SQLDatabase.from_uri(f"sqlite:///{path}", include_tables=['ShiftDownTimeDetails','ShiftProductionDetails'],sample_rows_in_table_info=0)
|
100 |
|
101 |
down_chain = chain(db=db1, llm=gemini)
|
102 |
prod_chain = chain(db=db2, llm=gemini)
|
@@ -115,22 +115,35 @@ def main():
|
|
115 |
("human", "{question}"+table_info)
|
116 |
]
|
117 |
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
118 |
sql_toolkit = SQLDatabaseToolkit(db=db3, llm=agent_llm)
|
119 |
agent = create_sql_agent(
|
120 |
toolkit=sql_toolkit,
|
121 |
llm=agent_llm,
|
122 |
agent_type=AgentType.ZERO_SHOT_REACT_DESCRIPTION,
|
123 |
verbose=True,
|
124 |
-
agent_executor_kwargs={"handle_parsing_errors":True}
|
125 |
)
|
126 |
|
127 |
def echo3(message, history):
|
128 |
answer = agent.invoke(prompt_agent.format_prompt(question=message))
|
129 |
-
|
|
|
130 |
|
131 |
downtime = gr.ChatInterface(fn=echo1, title="SQL-Chatbot", description="Q/A on Downtime details table")
|
132 |
production = gr.ChatInterface(fn=echo2, title="SQL-Chatbot", description="Q/A on Production details table")
|
133 |
-
agent_tab = gr.ChatInterface(fn=echo3, title="SQL-Chatbot", description="General Chatbot with self-thinking capability, more robust to questions.")
|
134 |
demo = gr.TabbedInterface([agent_tab, downtime, production], ['DB_bot-both tables','ShiftDownTimeDetails', 'ShiftProductionDetails'])
|
135 |
demo.launch(debug=True, share=True)
|
136 |
|
|
|
96 |
path = r"OPPI_shift.db" # \OPPI_down.db"
|
97 |
db1 = SQLDatabase.from_uri(f"sqlite:///{path}", include_tables=['ShiftDownTimeDetails'],sample_rows_in_table_info=0)
|
98 |
db2 = SQLDatabase.from_uri(f"sqlite:///{path}", include_tables=['ShiftProductionDetails'],sample_rows_in_table_info=0)
|
99 |
+
db3 = SQLDatabase.from_uri(f"sqlite:///{path}", include_tables=['ShiftDownTimeDetails','ShiftProductionDetails','Focas_AlarmHistory'],sample_rows_in_table_info=0)
|
100 |
|
101 |
down_chain = chain(db=db1, llm=gemini)
|
102 |
prod_chain = chain(db=db2, llm=gemini)
|
|
|
115 |
("human", "{question}"+table_info)
|
116 |
]
|
117 |
)
|
118 |
+
|
119 |
+
examples = [
|
120 |
+
"calculate total Prod quantity in Second Shift for 2024",
|
121 |
+
"Calculate total accepted parts in shift 2 for 2024",
|
122 |
+
"How many accepted parts were produced in October 2023 in each machine",
|
123 |
+
"How likely is the Turrent index aborted alarm expected on machine k-1",
|
124 |
+
"List all the distinct reasons behind DownTime in machine K-2",
|
125 |
+
"Calculate the total Downtime experienced by machine K-8 due to the reason of No Shift",
|
126 |
+
"What was the most common reason for Downtime in the year 2023?",
|
127 |
+
"Calculate the average downtime for Machine M-2 in for every month in later half of 2023",
|
128 |
+
"return all the reasons for Downcategory in Nov and dec on machine L-7 in 3rd shift",
|
129 |
+
]
|
130 |
sql_toolkit = SQLDatabaseToolkit(db=db3, llm=agent_llm)
|
131 |
agent = create_sql_agent(
|
132 |
toolkit=sql_toolkit,
|
133 |
llm=agent_llm,
|
134 |
agent_type=AgentType.ZERO_SHOT_REACT_DESCRIPTION,
|
135 |
verbose=True,
|
136 |
+
agent_executor_kwargs={"handle_parsing_errors":True, "return_intermediate_steps": True}
|
137 |
)
|
138 |
|
139 |
def echo3(message, history):
|
140 |
answer = agent.invoke(prompt_agent.format_prompt(question=message))
|
141 |
+
final_answer = f"Final Query:- {list(answer['intermediate_steps'][1][0])[-2][1].split('Action Input: ')[-1]}\n\nAnswer:- {answer['output']}"
|
142 |
+
return final_answer
|
143 |
|
144 |
downtime = gr.ChatInterface(fn=echo1, title="SQL-Chatbot", description="Q/A on Downtime details table")
|
145 |
production = gr.ChatInterface(fn=echo2, title="SQL-Chatbot", description="Q/A on Production details table")
|
146 |
+
agent_tab = gr.ChatInterface(fn=echo3, examples=examples, title="SQL-Chatbot", description="General Chatbot with self-thinking capability, more robust to questions.")
|
147 |
demo = gr.TabbedInterface([agent_tab, downtime, production], ['DB_bot-both tables','ShiftDownTimeDetails', 'ShiftProductionDetails'])
|
148 |
demo.launch(debug=True, share=True)
|
149 |
|