Spaces:
Sleeping
Sleeping
Create app_functions.py
Browse files- app_functions.py +29 -0
app_functions.py
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
|
|
| 1 |
from transformers import AutoModelForCausalLM, AutoTokenizer
|
| 2 |
|
| 3 |
def Get_DialoGPT_Response(input_text, no_words, user_type):
|
|
@@ -13,3 +14,31 @@ def Get_DialoGPT_Response(input_text, no_words, user_type):
|
|
| 13 |
return response
|
| 14 |
except Exception as e:
|
| 15 |
return f"Error during DialoGPT model execution: {str(e)}"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# app_functions.py
|
| 2 |
from transformers import AutoModelForCausalLM, AutoTokenizer
|
| 3 |
|
| 4 |
def Get_DialoGPT_Response(input_text, no_words, user_type):
|
|
|
|
| 14 |
return response
|
| 15 |
except Exception as e:
|
| 16 |
return f"Error during DialoGPT model execution: {str(e)}"
|
| 17 |
+
|
| 18 |
+
def Get_DistilGPT_Response(input_text, no_words, user_type):
|
| 19 |
+
model_name = "Rabbiaaa/DistilGPT"
|
| 20 |
+
try:
|
| 21 |
+
tokenizer = AutoTokenizer.from_pretrained(model_name)
|
| 22 |
+
model = AutoModelForCausalLM.from_pretrained(model_name)
|
| 23 |
+
|
| 24 |
+
prompt = f"Give an answer for {user_type} of the text given that is '{input_text}' within {no_words} words."
|
| 25 |
+
inputs = tokenizer(prompt, return_tensors="pt")
|
| 26 |
+
outputs = model.generate(inputs["input_ids"], max_new_tokens=int(no_words), do_sample=True, top_k=50)
|
| 27 |
+
response = tokenizer.decode(outputs[0], skip_special_tokens=True)
|
| 28 |
+
return response
|
| 29 |
+
except Exception as e:
|
| 30 |
+
return f"Error during DistilGPT model execution: {str(e)}"
|
| 31 |
+
|
| 32 |
+
def Get_MedGPT_Response(input_text, no_words, user_type):
|
| 33 |
+
model_name = "Rabbiaaa/MedGPT"
|
| 34 |
+
try:
|
| 35 |
+
tokenizer = AutoTokenizer.from_pretrained(model_name)
|
| 36 |
+
model = AutoModelForCausalLM.from_pretrained(model_name)
|
| 37 |
+
|
| 38 |
+
prompt = f"Give an answer for {user_type} of the text given that is '{input_text}' within {no_words} words."
|
| 39 |
+
inputs = tokenizer(prompt, return_tensors="pt")
|
| 40 |
+
outputs = model.generate(inputs["input_ids"], max_new_tokens=int(no_words), do_sample=True, top_k=50)
|
| 41 |
+
response = tokenizer.decode(outputs[0], skip_special_tokens=True)
|
| 42 |
+
return response
|
| 43 |
+
except Exception as e:
|
| 44 |
+
return f"Error during MedGPT model execution: {str(e)}"
|