MD1998 commited on
Commit
6f2882b
·
verified ·
1 Parent(s): 0015db3

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +18 -2
app.py CHANGED
@@ -3,12 +3,25 @@ from langchain.llms import HuggingFacePipeline
3
  from transformers import AutoTokenizer, AutoModel
4
  import transformers
5
  import torch
 
 
6
  import warnings
7
  warnings.filterwarnings('ignore')
8
 
 
9
  model = 'MD1998/FLAN-T5-V1'
10
  tokenizer=AutoTokenizer.from_pretrained(model)
11
 
 
 
 
 
 
 
 
 
 
 
12
  pipeline=transformers.pipeline(
13
  "text-generation",
14
  model=model,
@@ -26,10 +39,13 @@ pipeline=transformers.pipeline(
26
 
27
  llm=HuggingFacePipeline(pipeline=pipeline, model_kwargs={'temperature':0.1})
28
 
 
 
 
29
  def greet(prompt):
 
30
 
31
-
32
- return llm(prompt)
33
 
34
 
35
 
 
3
  from transformers import AutoTokenizer, AutoModel
4
  import transformers
5
  import torch
6
+ from langchain.prompts import PromptTemplate
7
+ from langchain.chains import LLMChain
8
  import warnings
9
  warnings.filterwarnings('ignore')
10
 
11
+
12
  model = 'MD1998/FLAN-T5-V1'
13
  tokenizer=AutoTokenizer.from_pretrained(model)
14
 
15
+ prompt_template=PromptTemplate(input_variables=["conversation"],
16
+ template="""\
17
+ You are a helpful, respectful, and honest assistant designed to improve English language skills. Always provide accurate and helpful responses to language improvement tasks, while ensuring safety and ethical standards. Your answers should not include any harmful, unethical, racist, sexist, toxic, dangerous, or illegal content. Please ensure that your responses are socially unbiased, positive, and focused on enhancing language skills.
18
+ If a question does not make sense or is not factually coherent, explain why instead of answering something incorrect. If you don't know the answer to a question, please don't share false information.
19
+ Your role is to guide users through various language exercises and challenges, helping them to practice and improve their English skills in a fun and engaging way. Always encourage users to try different approaches and provide constructive feedback to help them progress.
20
+
21
+ {conversation}
22
+ """)
23
+
24
+
25
  pipeline=transformers.pipeline(
26
  "text-generation",
27
  model=model,
 
39
 
40
  llm=HuggingFacePipeline(pipeline=pipeline, model_kwargs={'temperature':0.1})
41
 
42
+
43
+ chain = LLMChain(llm=llm, prompt=prompt_template, verbose=True)
44
+
45
  def greet(prompt):
46
+ response = chain.run(prompt)
47
 
48
+ return response
 
49
 
50
 
51