cececerece commited on
Commit
0da93dc
1 Parent(s): 5246e9e

Upload 2 files

Browse files
Files changed (2) hide show
  1. app.py +1 -2
  2. table_load.py +18 -1
app.py CHANGED
@@ -1,6 +1,5 @@
1
  import gradio as gr
2
  import table_load as tl
3
- import comm
4
 
5
 
6
  css="""
@@ -35,7 +34,7 @@ with gr.Blocks(css=css) as demo:
35
  load_table.click(tl.load_file, None, langchain_status, queue=False)
36
  load_table.click(tl.table_loader, inputs=[raw_table, openai_key], outputs=[langchain_status], queue=False)
37
 
38
- question.submit(comm.respond, [question, chatbot], [question, chatbot])
39
  clr_btn.click(lambda: None, None, chatbot, queue=False)
40
 
41
  demo.launch()
 
1
  import gradio as gr
2
  import table_load as tl
 
3
 
4
 
5
  css="""
 
34
  load_table.click(tl.load_file, None, langchain_status, queue=False)
35
  load_table.click(tl.table_loader, inputs=[raw_table, openai_key], outputs=[langchain_status], queue=False)
36
 
37
+ question.submit(tl.respond, [question, chatbot], [question, chatbot])
38
  clr_btn.click(lambda: None, None, chatbot, queue=False)
39
 
40
  demo.launch()
table_load.py CHANGED
@@ -1,4 +1,4 @@
1
- """functions related to tables loading"""
2
 
3
  def load_file():
4
  return "Loading..."
@@ -33,3 +33,20 @@ def table_loader(table_file, open_ai_key):
33
  else:
34
  return "Wrong file format! Upload excel file or csv!"
35
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """functions"""
2
 
3
  def load_file():
4
  return "Loading..."
 
33
  else:
34
  return "Wrong file format! Upload excel file or csv!"
35
 
36
+ def run(query):
37
+ from langchain.callbacks import get_openai_callback
38
+
39
+ with get_openai_callback() as cb:
40
+ response = (agent.run(query))
41
+ costs = (f"Total Cost (USD): ${cb.total_cost}")
42
+ output = f'{response} \n {costs}'
43
+ return output
44
+
45
+ def respond(message, chat_history):
46
+ import time
47
+
48
+ bot_message = run(message)
49
+ chat_history.append((message, bot_message))
50
+ time.sleep(0.5)
51
+ return "", chat_history
52
+