Update app.py
Browse files
app.py
CHANGED
@@ -1,28 +1,28 @@
|
|
1 |
import gradio as gr
|
2 |
-
from transformers import
|
3 |
|
4 |
-
def
|
5 |
-
model_name = "
|
6 |
tokenizer = AutoTokenizer.from_pretrained(model_name)
|
7 |
-
model =
|
8 |
|
9 |
-
inputs = tokenizer
|
10 |
-
outputs = model.generate(inputs,
|
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=
|
18 |
-
inputs=gr.Textbox(prompt="
|
19 |
outputs=gr.Textbox(),
|
20 |
live=True,
|
21 |
capture_session=True,
|
22 |
-
title="Chatbot",
|
23 |
-
description="Type your
|
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()
|