Spaces:
Sleeping
Sleeping
import gradio as gr | |
from datasets import load_dataset | |
# Load the WikiSQL dataset | |
wikisql_dataset = load_dataset("wikisql", split='train[:100]') # Load a subset of the dataset | |
# Create a mapping between natural language queries and SQL queries | |
query_sql_mapping = {item['question']: item['sql']['human_readable'] for item in wikisql_dataset} | |
def generate_sql_from_user_input(query): | |
# Look up the SQL query corresponding to the user's input | |
sql_query = query_sql_mapping.get(query, "No exact match found in the dataset.") | |
return sql_query | |
# Create a Gradio interface | |
interface = gr.Interface( | |
fn=generate_sql_from_user_input, | |
inputs=gr.Textbox(label="Enter your natural language query"), | |
outputs=gr.Textbox(label="SQL Query from Dataset"), | |
title="NL to SQL using WikiSQL Dataset", | |
description="This interface returns the SQL query from the WikiSQL dataset that exactly matches your natural language input." | |
) | |
# Launch the app | |
if __name__ == "__main__": | |
interface.launch() | |