AI Web Server
83C1A simple web server with a centered text input interface built using Flask.
This project is like a smart registration form that uses AI to chat with users. Here are the main parts:
-
Web Interface (
templates/index.html
,static/styles.css
,static/script.js
)- Shows a chat window where you can type messages
- Displays the collected information in real-time
- Uses basic HTML, CSS for looks, and JavaScript to handle user input
-
Web Server (
app.py
)- Built with Flask (a simple Python web framework)
- Receives messages from the chat
- Sends responses back to the browser
-
Chat Handler (
chat_handler.py
)- 🤖 The brain of the application
- ✨ Talks to OpenAI's API (like having a smart robot helper)
- Keeps track of what information we've collected
- Makes sure we get all the required details (name, username, password, workplace)
The cool part is how these pieces work together:
- You type a message
- JavaScript sends it to the Flask server
- The Chat Handler asks OpenAI what to say next
- The response comes back to your screen
Think of it like a relay race where each part passes the information to the next!
- Python 3.11 or higher
- Groq API key
- Clone or Download the repository
Download as Zip from GitHub ai-web-server or clone:
git clone <repository-url>
cd ai-web-server
- Install uv (if not already installed) For MacOS:
pip install uv
For Windows:
powershell -ExecutionPolicy ByPass -c "irm https://astral.sh/uv/install.ps1 | iex"
- Create a virtual environment
uv venv
- Activate the virtual environment For MacOS:
source .venv\scripts\activate
For Windows:
.venv\Scripts\activate
You might encounter an error about running scripts being disabled. If so, run the following command:
Set-ExecutionPolicy -Scope Process -ExecutionPolicy Bypass
# try activating the virtual environment again:
.venv\Scripts\activate
- Install dependencies
uv pip install -e .
-
Set up your Groq API key:
a. Get your API key:
- Go to Groq's website
- Sign up for an account if you don't have one
- Navigate to API Keys
- Click "Create API key"
- Copy your API key (make sure to save it as it won't be shown again)
b. Add your API key to the
.env
file in the project root:GROQ_API_KEY=your_api_key_here
Note: Replace
your_api_key_here
with your actual API key -
Run the server
uv run -m ai_web_server.app
Once the server is running, open your web browser and navigate to http://127.0.0.1:5000
- Never commit your
.env
file to version control - Keep your API key secret and secure
- The free tier API has rate limits and usage limits