File size: 1,784 Bytes
ec9ef8b 2ee70bc f24bed6 1f73097 f24bed6 2ee70bc f24bed6 1f73097 2ee70bc f24bed6 2ee70bc f24bed6 7b0e766 50de467 7b0e766 50de467 1f73097 23432db 50de467 1f73097 23432db 50de467 7b0e766 50de467 23432db 73a98e3 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
import gradio as gr
from transformers import AutoModelForQuestionAnswering, AutoTokenizer
from transformers import TapasTokenizer, TapasForQuestionAnswering
def execute_sql(user_query):
model_name = "microsoft/tapex-large-sql-execution" # Tapex large SQL execution model
tokenizer = AutoTokenizer.from_pretrained(model_name)
model = AutoModelForQuestionAnswering.from_pretrained(model_name)
inputs = tokenizer(user_query, return_tensors="pt", padding=True)
outputs = model(**inputs)
answer = tokenizer.decode(inputs['input_ids'][0][outputs['start_logits'].argmax():outputs['end_logits'].argmax() + 1])
return answer
'''
def chatbot_response(user_message):
# Your chatbot code goes here (using GPT-2 or any other text generation model)
# For example, you can use the GPT-2 code from the previous responses
return chatbot_generated_response
# Define the chatbot and SQL execution interface using Gradio
chatbot_interface = gr.Interface(
fn=chatbot_response,
inputs=gr.Textbox(prompt="You:"),
outputs=gr.Textbox(),
live=True,
capture_session=True,
title="Chatbot",
description="Type your message in the box above, and the chatbot will respond.",
)
'''
sql_execution_interface = gr.Interface(
fn=execute_sql,
inputs=gr.Textbox(prompt="Enter your SQL query:"),
outputs=gr.Textbox(),
live=True,
capture_session=True,
title="SQL Execution",
description="Type your SQL query in the box above, and the chatbot will execute it.",
)
# Combine the chatbot and SQL execution interfaces
#combined_interface = gr.Interface([chatbot_interface, sql_execution_interface], layout="horizontal")
# Launch the combined Gradio interface
if __name__ == "__main__":
sql_execution_interface.launch()
|