Skip to content

Commit 1d888f8

Browse files
authored
Merge pull request #166 from njwright92/simple-chatbot
README and updated simple chatbot with Phi
2 parents 48fb214 + 75c3d8e commit 1d888f8

File tree

11 files changed

+526
-0
lines changed

11 files changed

+526
-0
lines changed

simple-chatbot/README.md

+32
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
# 🤖 Simple Chatbot
2+
3+
![Chatbot Demo](chatbot-demo.gif) <!-- You can replace this with a real image or gif of your chatbot in action -->
4+
5+
## 🛠️ Description
6+
This project features a basic chatbot implemented in Python using the Hugging Face Transformers library. The chatbot engages in a text-based conversation with the user through a simple GUI. Although there might be a slight delay during the initial load due to the model being loaded into memory, once loaded, the chatbot is quite responsive and provides a delightful text-generation based interaction.
7+
8+
## ⚙️ Technologies Used
9+
- **Python 3:** Ensure you have Python 3 installed on your machine. You can download it from the [official website](https://www.python.org/downloads/).
10+
- **Hugging Face Transformers:** This project utilizes the Hugging Face Transformers library for text generation.
11+
12+
## 🌟 How to Run
13+
1. Clone the `python-mini-project` repository to your local machine.
14+
```bash
15+
git clone https://github.com/njwright92/python-mini-project.git
16+
```
17+
2. Navigate to the Simple_Chatbot folder within the projects directory.
18+
```bash
19+
cd python-mini-project/projects/Simple_Chatbot
20+
```
21+
3. Run the `chatbot.py` file.
22+
```bash
23+
python3 chatbot.py
24+
```
25+
26+
Engage with the chatbot through the GUI by typing your responses and pressing enter.
27+
28+
## 📺 Demo
29+
*Live gif of the chatbot in action coming soon.*
30+
31+
## 🤖 Author
32+
[Nate](https://njwright92.github.io/paper-kit-portfolio/)

simple-chatbot/chatbot.py

+62
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
import tkinter as tk
2+
from tkinter import Entry, scrolledtext
3+
from transformers import AutoTokenizer, AutoModelForCausalLM
4+
5+
# Load the model and tokenizer
6+
tokenizer = AutoTokenizer.from_pretrained("microsoft/phi-1_5")
7+
model = AutoModelForCausalLM.from_pretrained(
8+
"microsoft/phi-1_5", trust_remote_code=True)
9+
10+
# Function to generate a response from the model
11+
12+
13+
def generate_response(message):
14+
inputs = tokenizer(message, return_tensors='pt', truncation=True)
15+
outputs = model.generate(
16+
**inputs,
17+
max_length=150,
18+
pad_token_id=tokenizer.eos_token_id
19+
)
20+
response = tokenizer.decode(outputs[0], skip_special_tokens=True)
21+
return response
22+
23+
# Function to handle when the user sends a message
24+
25+
26+
def on_send(event=None): # event is passed by binders.
27+
message = user_input.get()
28+
if message: # Only process if there's a message
29+
# Display user message in the chat window
30+
chat_window.configure(state=tk.NORMAL) # Temporarily make it editable
31+
chat_window.insert(tk.END, f"You: {message}\n")
32+
chat_window.configure(state=tk.DISABLED) # Make it read-only again
33+
34+
# Clear the user input field
35+
user_input.delete(0, tk.END)
36+
37+
# Generate and display chatbot response
38+
response = generate_response(message)
39+
chat_window.configure(state=tk.NORMAL)
40+
chat_window.insert(tk.END, f"WebIdeasBot: {response}\n")
41+
chat_window.configure(state=tk.DISABLED)
42+
43+
44+
# Create the main window
45+
window = tk.Tk()
46+
window.title("WebIdeasBot")
47+
48+
# Create the chat window
49+
chat_window = scrolledtext.ScrolledText(
50+
window, width=80, height=20, state=tk.DISABLED)
51+
chat_window.pack()
52+
53+
# Create the user input field
54+
user_input = Entry(window, width=80)
55+
user_input.pack()
56+
user_input.focus_set() # Set focus to the input field
57+
58+
# Bind the Enter key to the on_send function
59+
user_input.bind("<Return>", on_send)
60+
61+
# Start the Tkinter event loop
62+
window.mainloop()

website-builder/.gitignore

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# .gitignore
2+
3+
# Ignore Python virtual environment files
4+
venv/
5+
__pycache__/
6+
7+
# Ignore configuration files
8+
config.py
9+
10+
# Ignore editor-specific files
11+
.vscode/
12+
.idea/
13+
*.pyc
14+
15+
# Ignore local development settings
16+
local_settings.py
17+
18+
# Ignore any files or directories you want to exclude
19+
__pycache__/

website-builder/README.md

+48
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
AI-Powered Website Builder
2+
Website Builder Logo coiming soon
3+
4+
5+
🛠️ Description
6+
7+
An innovative web application where users interact with an AI chatbot to design and generate custom-tailored websites. Users provide the specifications of their desired website, and the AI assists in creating a site based on these inputs.
8+
9+
⚙️ Languages or Frameworks Used
10+
11+
Backend: Python with Flask.
12+
Frontend: React/Angular (Choose based on your project).
13+
Required Modules:
14+
15+
Flask
16+
Flask-WTF (for forms)
17+
Jinja2
18+
And other modules...
19+
You can install the necessary modules using:
20+
21+
22+
Copy code
23+
pip install -r requirements.txt
24+
🌟 How to Run
25+
26+
Clone the repository:
27+
28+
Copy code
29+
git clone https://github.com/njwright92/python-mini-project.git
30+
cd website-builder
31+
32+
Install the required modules:
33+
34+
Copy code
35+
pip install -r requirements.txt
36+
Run the application:
37+
38+
39+
Copy code
40+
python run.py
41+
📺 Demo
42+
43+
Demo Screenshot
44+
coming soon
45+
46+
🤖 Author
47+
48+
Nate https://github.com/njwright92

website-builder/app/__init__.py

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
from flask import Flask
2+
from .routes import portfolio_routes
3+
from config import DevelopmentConfig, ProductionConfig
4+
5+
6+
def create_app():
7+
app = Flask(__name__)
8+
9+
# Choose the configuration based on your environment
10+
app.config.from_object(DevelopmentConfig) # For development environment
11+
# Uncomment the line below for production environment
12+
app.config.from_object(ProductionConfig)
13+
14+
# Register the blueprint
15+
app.register_blueprint(portfolio_routes.portfolio_bp,
16+
url_prefix='/portfolio')
17+
18+
# Other app configuration and routes...
19+
20+
return app
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
from flask import Blueprint, render_template
2+
3+
portfolio_bp = Blueprint('portfolio', __name__)
4+
5+
6+
@portfolio_bp.route('/create')
7+
def create_portfolio():
8+
# Your code for creating a portfolio goes here
9+
return render_template('create_portfolio.html') # Render the HTML template
10+
11+
12+
@portfolio_bp.route('/edit/<int:portfolio_id>')
13+
def edit_portfolio(portfolio_id):
14+
# Your code for editing a portfolio goes here
15+
return render_template('edit_portfolio.html') # Render the HTML template

website-builder/app/static/styles.css

+66
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
/* Reset default styles */
2+
* {
3+
margin: 0;
4+
padding: 0;
5+
box-sizing: border-box;
6+
}
7+
8+
/* Set a background color and font styles for the entire page */
9+
body {
10+
background-color: #f0f0f0;
11+
font-family: Arial, sans-serif;
12+
}
13+
14+
/* Header styles */
15+
header {
16+
background-color: #333;
17+
color: #fff;
18+
padding: 20px;
19+
text-align: center;
20+
}
21+
22+
/* Main content styles */
23+
main {
24+
max-width: 800px;
25+
margin: 20px auto;
26+
padding: 20px;
27+
background-color: #fff;
28+
box-shadow: 0px 0px 10px rgba(0, 0, 0, 0.1);
29+
border-radius: 5px;
30+
}
31+
32+
/* Form styles */
33+
form {
34+
display: flex;
35+
flex-direction: column;
36+
}
37+
38+
label {
39+
margin-bottom: 10px;
40+
font-weight: bold;
41+
}
42+
43+
input[type="text"],
44+
input[type="url"],
45+
textarea {
46+
padding: 10px;
47+
margin-bottom: 20px;
48+
border: 1px solid #ccc;
49+
border-radius: 5px;
50+
font-size: 16px;
51+
}
52+
53+
button {
54+
background-color: #333;
55+
color: #fff;
56+
padding: 10px 20px;
57+
border: none;
58+
border-radius: 5px;
59+
cursor: pointer;
60+
font-size: 18px;
61+
transition: background-color 0.3s;
62+
}
63+
64+
button:hover {
65+
background-color: #555;
66+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
4+
<head>
5+
<meta charset="UTF-8">
6+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
7+
<title>Create Portfolio</title>
8+
<link rel="stylesheet" type="text/css" href="{{ url_for('static', filename='styles.css') }}">
9+
10+
</head>
11+
12+
<body>
13+
<header>
14+
<h1>Create a New Portfolio</h1>
15+
</header>
16+
<main>
17+
<form action="{{ url_for('portfolio.create_portfolio') }}" method="POST">
18+
<!-- Add form fields for portfolio creation -->
19+
<label for="title">Title:</label>
20+
<input type="text" name="title" id="title" required>
21+
22+
<label for="description">Description:</label>
23+
<textarea name="description" id="description" rows="4" required></textarea>
24+
25+
<label for="image">Image URL:</label>
26+
<input type="url" name="image" id="image" required>
27+
28+
<button type="submit">Create Portfolio</button>
29+
</form>
30+
</main>
31+
<!-- Add a footer if needed -->
32+
</body>
33+
34+
</html>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
4+
<head>
5+
<meta charset="UTF-8">
6+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
7+
<title>Edit Portfolio</title>
8+
<link rel="stylesheet" type="text/css" href="{{ url_for('static', filename='styles.css') }}">
9+
10+
</head>
11+
12+
<body>
13+
<header>
14+
<h1>Edit Portfolio</h1>
15+
</header>
16+
<main>
17+
<form action="{{ url_for('portfolio.edit_portfolio', portfolio_id=portfolio.id) }}" method="POST">
18+
<!-- Add form fields for editing a portfolio -->
19+
<label for="title">Title:</label>
20+
<input type="text" name="title" id="title" value="{{ portfolio.title }}" required>
21+
22+
<label for="description">Description:</label>
23+
<textarea name="description" id="description" rows="4" required>{{ portfolio.description }}</textarea>
24+
25+
<label for="image">Image URL:</label>
26+
<input type="url" name="image" id="image" value="{{ portfolio.image }}" required>
27+
28+
<button type="submit">Save Changes</button>
29+
</form>
30+
</main>
31+
<!-- Add a footer if needed -->
32+
</body>
33+
34+
</html>

0 commit comments

Comments
 (0)