AstroLog is a web application that allows users to ask questions about a space mission database using natural language. It leverages Google's Gemini AI to convert user questions into SQL queries, executes them against an SQLite database, and displays the results in a user-friendly chat interface.
- Natural Language Queries: Ask questions like "Show me missions by SpaceX in 2023" or "What were the launch locations in August?".
- AI-Powered SQL Generation: Uses Google Gemini to translate questions into SQL queries.
- SQL Display: Shows the generated SQL query alongside the results for transparency.
- Tabular Results: Displays query results in a clear, formatted table.
- Chat History: Maintains conversation history within the user's session.
- Clear Chat: Option to clear the current chat session.
- Download Results: Allows downloading the tabular results as an XLSX (Excel) file.
- Responsive Design: Basic responsive layout using Bootstrap.
- Frontend: React, JavaScript, Bootstrap
- Backend: FastAPI, Python
- Database: SQLite
- AI Model: Google Gemini (via
google-generativeaiSDK) - Data Handling: Pandas (Backend)
-
Backend Setup:
-
Create a virtual environment (recommended):
python -m venv .venv
For Linux:
source .venv/bin/activateFor Windows:
.venv\Scripts\activate
-
Install Python dependencies:
pip install -r requirements.txt
-
Navigate to the backend directory:
cd backend -
First run sql.py to load csv in database
python sql.py
-
Create
.envfile: In thebackenddirectory, create a file named.envand add your credentials:GOOGLE_API_KEY=YOUR_GOOGLE_API_KEY SESSION_SECRET=GENERATE_A_STRONG_RANDOM_SECRET_KEY
-
Database: Ensure the
missions.dbSQLite database file exists in thebackenddirectory with the correct schema (seeGEMINI_SQL_PROMPTinmain.pyfor schema details).
-
-
Frontend Setup:
-
Navigate to the frontend directory:
cd ../frontend(from backend) orcd frontend(from root) -
Install Node.js dependencies:
npm i
-
-
Running the Application:
-
Start the Backend: In the
backenddirectory (with the virtual environment activated):uvicorn main:app --reload --port 8000
-
Start the Frontend: In the
frontenddirectory:npm run dev
-
Open your browser and navigate to
http://localhost:5173(or the port specified by Vite/React).
-
GET /api/chat: Retrieves the chat history for the current session.POST /api/chat: Sends a user message, triggers AI SQL generation and execution, returns the bot's response.DELETE /api/chat: Clears the chat history for the current session.GET /: Basic API root endpoint.
The backend requires the following environment variables set in a .env file within the backend directory:
GOOGLE_API_KEY: Your API key for Google AI Studio (Gemini).SESSION_SECRET: A strong, random secret key used for signing session cookies. "# astrolog" "# astrolog"