mouliraj56 commited on
Commit
dc07ea7
1 Parent(s): bec7b46

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +42 -0
app.py ADDED
@@ -0,0 +1,42 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ !pip install -q transformers einops accelerate langchain bitsandbytes
2
+
3
+ !nvidia-smi
4
+
5
+ from langchain import HuggingFacePipeline
6
+ from transformers import AutoTokenizer, pipeline
7
+ import torch
8
+
9
+ model = "tiiuae/falcon-7b-instruct" #tiiuae/falcon-40b-instruct
10
+
11
+ tokenizer = AutoTokenizer.from_pretrained(model)
12
+
13
+ pipeline = pipeline(
14
+ "text-generation", #task
15
+ model=model,
16
+ tokenizer=tokenizer,
17
+ torch_dtype=torch.bfloat16,
18
+ trust_remote_code=True,
19
+ device_map="auto",
20
+ max_length=200,
21
+ do_sample=True,
22
+ top_k=10,
23
+ num_return_sequences=1,
24
+ eos_token_id=tokenizer.eos_token_id
25
+ )
26
+
27
+
28
+ llm = HuggingFacePipeline(pipeline = pipeline, model_kwargs = {'temperature':0})
29
+
30
+ from langchain import PromptTemplate, LLMChain
31
+
32
+ template = """
33
+ You are an intelligent chatbot. Help the following question with brilliant answers.
34
+ Question: {question}
35
+ Answer:"""
36
+ prompt = PromptTemplate(template=template, input_variables=["question"])
37
+
38
+ llm_chain = LLMChain(prompt=prompt, llm=llm)
39
+
40
+ question = "Explain what is Artificial Intellience as Nursery Rhymes "
41
+
42
+ print(llm_chain.run(question))