Abhay1210 commited on
Commit
821717a
1 Parent(s): 779b079

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +43 -0
app.py ADDED
@@ -0,0 +1,43 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ pip -q install langchain huggingface_hub transformers sentence_transformers accelerate bitsandbytes
2
+
3
+ import os
4
+ os.environ['HUGGINGFACEHUB_API_TOKEN'] = prompttoken
5
+
6
+ from langchain import PromptTemplate, HuggingFaceHub, LLMChain
7
+
8
+ template = """Question: {question}
9
+ Answer: Let's think step by step."""
10
+
11
+ prompt = PromptTemplate(template=template, input_variables=["question"])
12
+
13
+ llm_chain = LLMChain(prompt=prompt,
14
+ llm=HuggingFaceHub(repo_id="google/flan-t5-xl",
15
+ model_kwargs={"temperature":0,
16
+ "max_length":64}))
17
+
18
+
19
+ from langchain.llms import HuggingFacePipeline
20
+ import torch
21
+ from transformers import AutoTokenizer, AutoModelForCausalLM, pipeline, AutoModelForSeq2SeqLM, AutoTokenizer, AutoModelForSeq2SeqLM
22
+
23
+ model_id = 'Kaludi/chatgpt-gpt4-prompts-bart-large-cnn-samsum'
24
+ tokenizer = AutoTokenizer.from_pretrained(model_id)
25
+ model = AutoModelForSeq2SeqLM.from_pretrained(model_id, from_tf=True)
26
+
27
+ pipeline = pipeline(
28
+ "text2text-generation",
29
+ model=model,
30
+ tokenizer=tokenizer,
31
+ max_length=128
32
+ )
33
+
34
+ local_llm = HuggingFacePipeline(pipeline=pipeline)
35
+
36
+
37
+ llm_chain = LLMChain(prompt=prompt,
38
+ llm=local_llm
39
+ )
40
+
41
+ question = "Excel Sheet"
42
+
43
+ print(llm_chain.run(question))