https://github.com/aryamnsls/chatgptclone
A ChatGPT Clone using GPT-4 Turbo is an AI-powered chatbot application that mimics ChatGPT's conversational abilities. It leverages OpenAIβs GPT-4 Turbo API for generating human-like responses, enabling real-time interaction. The clone includes features like chat history, user authentication, and responsive UI
https://github.com/aryamnsls/chatgptclone
expressjs flask html-css-javascript mongodb nodejs openai python
Last synced: 3 months ago
JSON representation
A ChatGPT Clone using GPT-4 Turbo is an AI-powered chatbot application that mimics ChatGPT's conversational abilities. It leverages OpenAIβs GPT-4 Turbo API for generating human-like responses, enabling real-time interaction. The clone includes features like chat history, user authentication, and responsive UI
- Host: GitHub
- URL: https://github.com/aryamnsls/chatgptclone
- Owner: Aryamnsls
- Created: 2025-04-08T11:55:45.000Z (about 1 year ago)
- Default Branch: main
- Last Pushed: 2025-04-08T12:06:09.000Z (about 1 year ago)
- Last Synced: 2025-04-08T12:35:16.752Z (about 1 year ago)
- Topics: expressjs, flask, html-css-javascript, mongodb, nodejs, openai, python
- Language: CSS
- Homepage: https://react-chatgpt-clone-eight.vercel.app/
- Size: 0 Bytes
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 4
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
Sure! Here's a **step-by-step guide** to build a **ChatGPT Clone** using π **Python**, βοΈ **Flask**, π **OpenAI**, π **MongoDB**, and π§± **HTML** for the frontend β complete with some beautiful emojis to keep it fun and clear! π
---
### π‘ Step-by-Step Procedure to Build a ChatGPT Clone
---
#### 1οΈβ£ **Setup Your Project Environment**
- π Create a folder for your project
- βοΈ Create a virtual environment and activate it:
```bash
python -m venv venv
source venv/bin/activate # macOS/Linux
venv\Scripts\activate # Windows
```
---
#### 2οΈβ£ **Install Required Libraries**
```bash
pip install flask pymongo dnspython openai python-dotenv
```
---
#### 3οΈβ£ **Create Your Project Structure**
```
chatgpt_clone/
β
βββ app.py π§ Main Flask app
βββ templates/
β βββ index.html πΌοΈ Frontend HTML
βββ static/
β βββ style.css π¨ CSS Styling
βββ .env π Store API Keys
βββ db.py π MongoDB Functions
```
---
#### 4οΈβ£ **Configure .env File for Security** π
```dotenv
OPENAI_API_KEY=your_openai_api_key
MONGO_URI=your_mongodb_connection_string
```
---
#### 5οΈβ£ **Connect to MongoDB (db.py)** π
```python
from pymongo import MongoClient
import os
from dotenv import load_dotenv
load_dotenv()
client = MongoClient(os.getenv("MONGO_URI"))
db = client.chatgpt_clone
chat_collection = db.chats
```
---
#### 6οΈβ£ **Create Flask App (app.py)** βοΈ
```python
from flask import Flask, render_template, request, jsonify
from dotenv import load_dotenv
import openai
import os
from db import chat_collection
load_dotenv()
openai.api_key = os.getenv("OPENAI_API_KEY")
app = Flask(__name__)
@app.route('/')
def index():
return render_template('index.html')
@app.route('/ask', methods=['POST'])
def ask():
user_input = request.json['message']
response = openai.ChatCompletion.create(
model="gpt-4-turbo",
messages=[{"role": "user", "content": user_input}]
)
reply = response['choices'][0]['message']['content']
# Save to MongoDB
chat_collection.insert_one({"user": user_input, "bot": reply})
return jsonify({'reply': reply})
if __name__ == '__main__':
app.run(debug=True)
```
---
#### 7οΈβ£ **Design the HTML (templates/index.html)** π§±
```html
π¬ ChatGPT Clone
π€ ChatGPT Clone
π Send
async function sendMessage() {
const input = document.getElementById("user-input").value;
const res = await fetch('/ask', {
method: 'POST',
headers: {'Content-Type': 'application/json'},
body: JSON.stringify({message: input})
});
const data = await res.json();
const chatBox = document.getElementById("chat-box");
chatBox.innerHTML += `<p>π§βπ» You: ${input}</p>`;
chatBox.innerHTML += `<p>π€ Bot: ${data.reply}</p>`;
}
```
---
#### 8οΈβ£ **Add Styling (static/style.css)** π¨
```css
body {
font-family: 'Segoe UI', sans-serif;
background-color: #f4f4f9;
text-align: center;
padding: 2em;
}
#chat-box {
border: 1px solid #ccc;
padding: 1em;
margin: 1em auto;
width: 60%;
height: 300px;
overflow-y: scroll;
background-color: #fff;
border-radius: 10px;
}
input {
width: 40%;
padding: 10px;
margin-top: 10px;
border-radius: 5px;
}
button {
padding: 10px 20px;
margin-left: 10px;
border-radius: 5px;
background-color: #007bff;
color: white;
cursor: pointer;
}
```
---
#### 9οΈβ£ **Run Your Application** πββοΈ
```bash
python app.py
```
Visit: [http://localhost:5000](http://localhost:5000) π
---
#### π **(Optional) Enhance Features**
β¨ Add features like:
- Chat history display from MongoDB
- User authentication (Login/Signup)
- Multiple users
- Admin analytics dashboard π
---
### β
Done! Youβve built a mini ChatGPT clone!
Let me know if you'd like to deploy it on **Render**, **Vercel**, or **Heroku** π or if you want to add advanced features!