Create README.md
Browse files
README.md
ADDED
@@ -0,0 +1,37 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from transformers import GPT3Tokenizer, GPT3LMHeadModel
|
2 |
+
|
3 |
+
# Load the tokenizer
|
4 |
+
tokenizer = GPT3Tokenizer.from_pretrained("gpt-3.5-turbo")
|
5 |
+
|
6 |
+
# Load the model
|
7 |
+
model = GPT3LMHeadModel.from_pretrained("gpt-3.5-turbo")
|
8 |
+
|
9 |
+
# Define the conversation loop
|
10 |
+
while True:
|
11 |
+
# Capture user input
|
12 |
+
user_input = input("User: ")
|
13 |
+
|
14 |
+
# Format user input as prompts
|
15 |
+
prompts = ["User: " + user_input]
|
16 |
+
|
17 |
+
# Generate model response
|
18 |
+
model_output = model.generate(tokenizer.encode(prompts, return_tensors="pt"), max_length=100)
|
19 |
+
|
20 |
+
# Extract and display model-generated response
|
21 |
+
model_response = tokenizer.decode(model_output[0], skip_special_tokens=True)
|
22 |
+
print("Bot: " + model_response)
|
23 |
+
|
24 |
+
from flask import Flask, request, jsonify
|
25 |
+
|
26 |
+
app = Flask(__name__)
|
27 |
+
|
28 |
+
@app.route('/chatbot', methods=['POST'])
|
29 |
+
def chatbot():
|
30 |
+
user_input = request.json['user_input']
|
31 |
+
prompts = ["User: " + user_input]
|
32 |
+
model_output = model.generate(tokenizer.encode(prompts, return_tensors="pt"), max_length=100)
|
33 |
+
model_response = tokenizer.decode(model_output[0], skip_special_tokens=True)
|
34 |
+
return jsonify({'bot_response': model_response})
|
35 |
+
|
36 |
+
if __name__ == '__main__':
|
37 |
+
app.run(debug=True)
|