Update app.py
Browse files
app.py
CHANGED
|
@@ -1,10 +1,11 @@
|
|
| 1 |
from flask import Flask, request, jsonify
|
| 2 |
-
from transformers import pipeline
|
| 3 |
|
| 4 |
app = Flask(__name__)
|
| 5 |
|
| 6 |
-
# Initialize the Hugging Face
|
| 7 |
-
chatbot = pipeline("
|
|
|
|
| 8 |
|
| 9 |
# Example restaurant data
|
| 10 |
menu = {
|
|
@@ -23,8 +24,13 @@ def chat():
|
|
| 23 |
# Get user input from the frontend
|
| 24 |
user_input = request.json.get('user_input', '')
|
| 25 |
|
| 26 |
-
#
|
| 27 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 28 |
chatbot_reply = response[0]['generated_text']
|
| 29 |
|
| 30 |
# Match user preference to the menu (based on keywords in the input)
|
|
|
|
| 1 |
from flask import Flask, request, jsonify
|
| 2 |
+
from transformers import pipeline, set_seed
|
| 3 |
|
| 4 |
app = Flask(__name__)
|
| 5 |
|
| 6 |
+
# Initialize the Hugging Face text-generation pipeline (DialoGPT model)
|
| 7 |
+
chatbot = pipeline("text-generation", model="microsoft/DialoGPT-medium")
|
| 8 |
+
set_seed(42)
|
| 9 |
|
| 10 |
# Example restaurant data
|
| 11 |
menu = {
|
|
|
|
| 24 |
# Get user input from the frontend
|
| 25 |
user_input = request.json.get('user_input', '')
|
| 26 |
|
| 27 |
+
# Add user input to the conversation history (we'll use a simple list to store history)
|
| 28 |
+
conversation_history = user_input
|
| 29 |
+
|
| 30 |
+
# Generate a response from the chatbot model using text generation
|
| 31 |
+
response = chatbot(conversation_history, max_length=100, num_return_sequences=1, pad_token_id=50256)
|
| 32 |
+
|
| 33 |
+
# Get the chatbot's response text
|
| 34 |
chatbot_reply = response[0]['generated_text']
|
| 35 |
|
| 36 |
# Match user preference to the menu (based on keywords in the input)
|