teaevo commited on
Commit
1f73097
·
1 Parent(s): 23432db

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +11 -11
app.py CHANGED
@@ -1,28 +1,28 @@
1
  import gradio as gr
2
- from transformers import AutoModelForCausalLM, AutoTokenizer
3
 
4
- def chatbot_response(user_message):
5
- model_name = "gpt2" # You can change this to any other model from the list above
6
  tokenizer = AutoTokenizer.from_pretrained(model_name)
7
- model = AutoModelForCausalLM.from_pretrained(model_name)
8
 
9
- inputs = tokenizer.encode("User: " + user_message, return_tensors="pt")
10
- outputs = model.generate(inputs, max_length=100, num_return_sequences=1)
11
  response = tokenizer.decode(outputs[0], skip_special_tokens=True)
12
 
13
  return response
14
 
15
  # Define the chatbot interface using Gradio
16
  iface = gr.Interface(
17
- fn=chatbot_response,
18
- inputs=gr.Textbox(prompt="You:"),
19
  outputs=gr.Textbox(),
20
  live=True,
21
  capture_session=True,
22
- title="Chatbot",
23
- description="Type your message in the box above, and the chatbot will respond.",
24
  )
25
 
26
  # Launch the Gradio interface
27
  if __name__ == "__main__":
28
- iface.launch()
 
1
  import gradio as gr
2
+ from transformers import AutoModelForSeq2SeqLM, AutoTokenizer
3
 
4
+ def execute_sql(user_query):
5
+ model_name = "microsoft/tapex-large-sql-execution" # Tapex large SQL execution model
6
  tokenizer = AutoTokenizer.from_pretrained(model_name)
7
+ model = AutoModelForSeq2SeqLM.from_pretrained(model_name)
8
 
9
+ inputs = tokenizer(user_query, return_tensors="pt", padding=True)
10
+ outputs = model.generate(inputs['input_ids'], attention_mask=inputs['attention_mask'], max_length=1024)
11
  response = tokenizer.decode(outputs[0], skip_special_tokens=True)
12
 
13
  return response
14
 
15
  # Define the chatbot interface using Gradio
16
  iface = gr.Interface(
17
+ fn=execute_sql,
18
+ inputs=gr.Textbox(prompt="Enter your SQL query:"),
19
  outputs=gr.Textbox(),
20
  live=True,
21
  capture_session=True,
22
+ title="SQL Execution Chatbot",
23
+ description="Type your SQL query in the box above, and the chatbot will execute it.",
24
  )
25
 
26
  # Launch the Gradio interface
27
  if __name__ == "__main__":
28
+ iface.launch()