Rabbiaaa commited on
Commit
54f53fd
·
verified ·
1 Parent(s): 47b4748

Create app_functions.py

Browse files
Files changed (1) hide show
  1. app_functions.py +15 -0
app_functions.py ADDED
@@ -0,0 +1,15 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from transformers import AutoModelForCausalLM, AutoTokenizer
2
+
3
+ def Get_DialoGPT_Response(input_text, no_words, user_type):
4
+ model_name = "Rabbiaaa/DialoGPT"
5
+ try:
6
+ tokenizer = AutoTokenizer.from_pretrained(model_name)
7
+ model = AutoModelForCausalLM.from_pretrained(model_name)
8
+
9
+ prompt = f"Give an answer for {user_type} of the text given that is '{input_text}' within {no_words} words."
10
+ inputs = tokenizer(prompt, return_tensors="pt")
11
+ outputs = model.generate(inputs["input_ids"], max_new_tokens=int(no_words), do_sample=True, top_k=50)
12
+ response = tokenizer.decode(outputs[0], skip_special_tokens=True)
13
+ return response
14
+ except Exception as e:
15
+ return f"Error during DialoGPT model execution: {str(e)}"