teaevo commited on
Commit
32680f1
·
1 Parent(s): 2ee70bc

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +13 -35
app.py CHANGED
@@ -1,50 +1,28 @@
1
  import gradio as gr
2
  from transformers import AutoModelForQuestionAnswering, AutoTokenizer
3
- from transformers import TapasTokenizer, TapasForQuestionAnswering
4
 
5
- def execute_sql(user_query):
6
- model_name = "microsoft/tapex-large-sql-execution" # Tapex large SQL execution model
7
- tokenizer = AutoTokenizer.from_pretrained(model_name)
8
- model = AutoModelForQuestionAnswering.from_pretrained(model_name)
9
 
10
- inputs = tokenizer(user_query, return_tensors="pt", padding=True)
 
11
  outputs = model(**inputs)
12
  answer = tokenizer.decode(inputs['input_ids'][0][outputs['start_logits'].argmax():outputs['end_logits'].argmax() + 1])
13
-
14
  return answer
15
 
16
- '''
17
- def chatbot_response(user_message):
18
- # Your chatbot code goes here (using GPT-2 or any other text generation model)
19
- # For example, you can use the GPT-2 code from the previous responses
20
-
21
- return chatbot_generated_response
22
-
23
- # Define the chatbot and SQL execution interface using Gradio
24
- chatbot_interface = gr.Interface(
25
- fn=chatbot_response,
26
- inputs=gr.Textbox(prompt="You:"),
27
- outputs=gr.Textbox(),
28
- live=True,
29
- capture_session=True,
30
- title="Chatbot",
31
- description="Type your message in the box above, and the chatbot will respond.",
32
- )
33
- '''
34
-
35
- sql_execution_interface = gr.Interface(
36
  fn=execute_sql,
37
- inputs=gr.Textbox(prompt="Enter your SQL query:"),
38
  outputs=gr.Textbox(),
39
  live=True,
40
  capture_session=True,
41
- title="SQL Execution",
42
- description="Type your SQL query in the box above, and the chatbot will execute it.",
43
  )
44
 
45
- # Combine the chatbot and SQL execution interfaces
46
- #combined_interface = gr.Interface([chatbot_interface, sql_execution_interface], layout="horizontal")
47
-
48
- # Launch the combined Gradio interface
49
  if __name__ == "__main__":
50
- sql_execution_interface.launch()
 
1
  import gradio as gr
2
  from transformers import AutoModelForQuestionAnswering, AutoTokenizer
 
3
 
4
+ # Load the Tapas model and tokenizer
5
+ model_name = "google/tapas-large-finetuned-wtq"
6
+ tokenizer = AutoTokenizer.from_pretrained(model_name)
7
+ model = AutoModelForQuestionAnswering.from_pretrained(model_name)
8
 
9
+ def execute_sql(user_query):
10
+ inputs = tokenizer(user_query, return_tensors="pt")
11
  outputs = model(**inputs)
12
  answer = tokenizer.decode(inputs['input_ids'][0][outputs['start_logits'].argmax():outputs['end_logits'].argmax() + 1])
 
13
  return answer
14
 
15
+ # Define the chatbot interface using Gradio
16
+ iface = gr.Interface(
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
17
  fn=execute_sql,
18
+ inputs=gr.Textbox(prompt="Enter your question:"),
19
  outputs=gr.Textbox(),
20
  live=True,
21
  capture_session=True,
22
+ title="Database Question Answering Chatbot",
23
+ description="Type your questions about the database in the box above, and the chatbot will provide answers.",
24
  )
25
 
26
+ # Launch the Gradio interface
 
 
 
27
  if __name__ == "__main__":
28
+ iface.launch()