Spaces:
Sleeping
Sleeping
Update main.py and README.md version 1.1.0
Browse files- Update menu and selected model
- Create a README.md
- README.md +62 -1
- backend/app/main.py +46 -4
README.md
CHANGED
|
@@ -1 +1,62 @@
|
|
| 1 |
-
# NL2SQL
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# NL2SQL
|
| 2 |
+
A backend Command Line Interface (CLI) framework designed to evaluate and test various NL2SQL models.
|
| 3 |
+
|
| 4 |
+
**Note:** The frontend interface for this application is currently in progress and not yet available. All interactions are handled via the CLI.
|
| 5 |
+
|
| 6 |
+
## Prerequisites & Installation
|
| 7 |
+
|
| 8 |
+
To run this CLI tool locally, follow these steps to set up your environment:
|
| 9 |
+
|
| 10 |
+
1. Activate the Virtual Environment.
|
| 11 |
+
|
| 12 |
+
- **Windows**: venv\Scripts\Activate
|
| 13 |
+
- **macOS/Linux**: source venv/bin/activate
|
| 14 |
+
|
| 15 |
+
2. Install Requirements
|
| 16 |
+
- Ensure a *requirements.txt* file exists in your project backend folder.
|
| 17 |
+
|
| 18 |
+
>> pip install -r requirements.txt
|
| 19 |
+
|
| 20 |
+
3. Configure Environment Variable (.env)
|
| 21 |
+
|
| 22 |
+
**Note: Users must generate your own free access token from yiur https://huggingface.co/settings/tokens to avoid rate limits.**
|
| 23 |
+
|
| 24 |
+
1. Create a *.env* file in the *backend/* directory
|
| 25 |
+
|
| 26 |
+
2. Add your Hugging Face *Read* Token to the file.
|
| 27 |
+
|
| 28 |
+
# Example .env file
|
| 29 |
+
HF_TOKEN=your_hugging_face_read_token_here
|
| 30 |
+
|
| 31 |
+
## Usage Guide
|
| 32 |
+
|
| 33 |
+
Once your environment is set up and your token is configured, you can run the CLI application.
|
| 34 |
+
|
| 35 |
+
1. Navigate to the Backend Directory
|
| 36 |
+
|
| 37 |
+
>> cd backend
|
| 38 |
+
|
| 39 |
+
2. Launch the Application
|
| 40 |
+
|
| 41 |
+
>> python -m app.main
|
| 42 |
+
|
| 43 |
+
3. Interacting with the CLI Menu Upon running the command, you will be presented with a main menu. Choose the number corresponding to your desired action:
|
| 44 |
+
|
| 45 |
+
1. Running Question to SQL Test: Evaluates how well a model translates natural language queries into executable SQL commands.
|
| 46 |
+
|
| 47 |
+
2. Running Question Answering Test: Evaluates the end-to-end process (Question -> SQL -> Database Execution -> Natural Language Answer).
|
| 48 |
+
|
| 49 |
+
3. Exit/Quit: Closes the application.
|
| 50 |
+
|
| 51 |
+
4. Model Selection & Batch Testing
|
| 52 |
+
|
| 53 |
+
After selecting either option 1 or 2, the CLI will display a list of available NL2SQL models.
|
| 54 |
+
|
| 55 |
+
Enter the number/name of the model you wish to test.
|
| 56 |
+
|
| 57 |
+
Automatic Execution: Once a model is selected, the system will automatically begin running the batch test against the scenarios defined in scripts/test_cases.json. Sit back and wait for the reports to generate in your root folder!
|
| 58 |
+
|
| 59 |
+
## 🚧 Roadmap
|
| 60 |
+
- Development and integration of a graphical User Interface (Frontend).
|
| 61 |
+
|
| 62 |
+
- Additional database schema support.
|
backend/app/main.py
CHANGED
|
@@ -2,6 +2,7 @@
|
|
| 2 |
# Main entry point for the NL2SQL application
|
| 3 |
import os
|
| 4 |
from dotenv import load_dotenv
|
|
|
|
| 5 |
from src.scripts.interactive_mode import run_interactiveMode
|
| 6 |
from src.scripts.evaluation_mode import run_evaluation
|
| 7 |
|
|
@@ -11,23 +12,64 @@ hf_token = os.getenv("HF_TOKEN")
|
|
| 11 |
if not hf_token:
|
| 12 |
raise ValueError("HuggingFace API token not found!")
|
| 13 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 14 |
def main():
|
| 15 |
"""Main application entry point and interactive menu"""
|
| 16 |
while True:
|
| 17 |
print("\n" + "="*30)
|
| 18 |
print(" NL2SQL Application Main Menu")
|
| 19 |
print("\n" + "="*30)
|
| 20 |
-
print("1. Run Interactive Agent NL2SQL Mode (
|
| 21 |
-
print("2. Run Batch Evaluation of NL2SQL Agent (
|
| 22 |
print("3. Exit")
|
| 23 |
print("\n" + "="*30)
|
| 24 |
|
| 25 |
choice = input("Select an option (1-3): ")
|
| 26 |
|
| 27 |
if choice == '1':
|
| 28 |
-
|
|
|
|
|
|
|
| 29 |
elif choice == '2':
|
| 30 |
-
|
|
|
|
|
|
|
| 31 |
elif choice == '3':
|
| 32 |
print("Exiting application. Goodbye!")
|
| 33 |
break
|
|
|
|
| 2 |
# Main entry point for the NL2SQL application
|
| 3 |
import os
|
| 4 |
from dotenv import load_dotenv
|
| 5 |
+
from src.nl2sql.hf_engine import get_models, DEFAULT_MODEL_ID
|
| 6 |
from src.scripts.interactive_mode import run_interactiveMode
|
| 7 |
from src.scripts.evaluation_mode import run_evaluation
|
| 8 |
|
|
|
|
| 12 |
if not hf_token:
|
| 13 |
raise ValueError("HuggingFace API token not found!")
|
| 14 |
|
| 15 |
+
def select_model() -> str:
|
| 16 |
+
"""
|
| 17 |
+
Allow user to choose NL2SQL models available.
|
| 18 |
+
"""
|
| 19 |
+
available_models = get_models()
|
| 20 |
+
print("\n" + "="*30)
|
| 21 |
+
print(" Select Model for Testing:")
|
| 22 |
+
print("\n***Press q to quit at any time.")
|
| 23 |
+
print("\n" + "="*30)
|
| 24 |
+
|
| 25 |
+
for i, model in enumerate(available_models, 1):
|
| 26 |
+
print(f"{i}. {model}")
|
| 27 |
+
print(f"{len(available_models) + 1}. Use Default [Recommended]: ({DEFAULT_MODEL_ID})")
|
| 28 |
+
print("\n" + "-"*50)
|
| 29 |
+
|
| 30 |
+
while True:
|
| 31 |
+
choice = input(f"Select a model (1-{len(available_models) + 1}) or 'q' to quit: ")
|
| 32 |
+
|
| 33 |
+
if choice.lower() == 'q':
|
| 34 |
+
print("Returning to main menu.")
|
| 35 |
+
return None
|
| 36 |
+
|
| 37 |
+
try:
|
| 38 |
+
choice = int(choice)
|
| 39 |
+
|
| 40 |
+
if 1 <= choice <= len(available_models):
|
| 41 |
+
selected = available_models[choice-1]
|
| 42 |
+
print(f"\n[+] Active Model set to: {selected}")
|
| 43 |
+
return selected
|
| 44 |
+
elif choice == len(available_models) + 1:
|
| 45 |
+
print(f"\n[+] Active Model set to Default: {DEFAULT_MODEL_ID}")
|
| 46 |
+
return DEFAULT_MODEL_ID
|
| 47 |
+
else:
|
| 48 |
+
print("Invalid range. Please select a valid option.")
|
| 49 |
+
except ValueError:
|
| 50 |
+
print("Invalid input. Please enter a number corresponding to the model choice.")
|
| 51 |
+
|
| 52 |
def main():
|
| 53 |
"""Main application entry point and interactive menu"""
|
| 54 |
while True:
|
| 55 |
print("\n" + "="*30)
|
| 56 |
print(" NL2SQL Application Main Menu")
|
| 57 |
print("\n" + "="*30)
|
| 58 |
+
print("1. Run Interactive Agent NL2SQL Mode (Question Answering Evaluation)")
|
| 59 |
+
print("2. Run Batch Evaluation of NL2SQL Agent (Question to SQL Evaluation)")
|
| 60 |
print("3. Exit")
|
| 61 |
print("\n" + "="*30)
|
| 62 |
|
| 63 |
choice = input("Select an option (1-3): ")
|
| 64 |
|
| 65 |
if choice == '1':
|
| 66 |
+
selected_model = select_model()
|
| 67 |
+
if selected_model:
|
| 68 |
+
run_interactiveMode(model_id=selected_model)
|
| 69 |
elif choice == '2':
|
| 70 |
+
selected_model = select_model()
|
| 71 |
+
if selected_model:
|
| 72 |
+
run_evaluation(model_id=selected_model)
|
| 73 |
elif choice == '3':
|
| 74 |
print("Exiting application. Goodbye!")
|
| 75 |
break
|