English
shivanircodel commited on
Commit
40f2a33
1 Parent(s): 8c64677

Update feedback.py

Browse files
Files changed (1) hide show
  1. feedback.py +28 -13
feedback.py CHANGED
@@ -1,18 +1,33 @@
1
- from transformers import GPT3LMHeadModel, GPT3Tokenizer
 
2
 
3
- # Load pre-trained model and tokenizer
4
- model_name = "gpt3" # You could choose another model here
5
- model = GPT2LMHeadModel.from_pretrained(model_name)
6
- tokenizer = GPT2Tokenizer.from_pretrained(model_name)
7
 
8
- def generate_feedback(user_answer):
9
- # Encode user input to model's input format
10
- inputs = tokenizer.encode(user_answer, return_tensors='pt')
11
-
12
- # Generate response from the model
13
- outputs = model.generate(inputs, max_length=150, num_return_sequences=1, no_repeat_ngram_size=2)
14
 
15
- # Decode the model's output to text
 
 
 
16
  feedback = tokenizer.decode(outputs[0], skip_special_tokens=True)
17
-
18
  return feedback
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from flask import Flask, render_template, request
2
+ from transformers import GPT2LMHeadModel, GPT2Tokenizer
3
 
4
+ app = Flask(__name__)
 
 
 
5
 
6
+ # Load the fine-tuned model and tokenizer
7
+ model = GPT2LMHeadModel.from_pretrained("./fine_tuned_model")
8
+ tokenizer = GPT2Tokenizer.from_pretrained("./fine_tuned_model")
 
 
 
9
 
10
+ # Function to generate feedback
11
+ def generate_feedback(user_input):
12
+ inputs = tokenizer(user_input, return_tensors="pt", truncation=True, padding=True, max_length=512)
13
+ outputs = model.generate(inputs["input_ids"], max_length=150, num_return_sequences=1)
14
  feedback = tokenizer.decode(outputs[0], skip_special_tokens=True)
 
15
  return feedback
16
+
17
+ @app.route('/')
18
+ def index():
19
+ return render_template('behavioral.html')
20
+
21
+ @app.route('/submit_answer', methods=['POST'])
22
+ def submit_answer():
23
+ # Get the user input from the form
24
+ user_input = request.form['answer'] # Assuming the form uses 'answer' as input field name
25
+
26
+ # Generate feedback using the fine-tuned model
27
+ feedback = generate_feedback(user_input)
28
+
29
+ # Return the feedback to the user and render it in behavioral.html
30
+ return render_template('behavioral.html', feedback=feedback)
31
+
32
+ if __name__ == '__main__':
33
+ app.run(debug=True)