Swathi6 commited on
Commit
b79e85a
·
verified ·
1 Parent(s): b88ea02

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +11 -5
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 chatbot model (using DialoGPT for simplicity)
7
- chatbot = pipeline("conversational", model="microsoft/DialoGPT-medium")
 
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
- # Generate a response from the chatbot model
27
- response = chatbot(user_input)
 
 
 
 
 
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)