Update app.py
Browse files
app.py
CHANGED
@@ -1,42 +1,20 @@
|
|
1 |
-
from
|
2 |
-
from auto_gptq import AutoGPTQForCausalLM, BaseQuantizeConfig
|
3 |
|
4 |
-
|
5 |
-
|
6 |
-
use_triton = False
|
7 |
-
|
8 |
-
tokenizer = AutoTokenizer.from_pretrained(model_name, use_fast=True)
|
9 |
-
|
10 |
-
model = AutoGPTQForCausalLM.from_quantized(model_name,
|
11 |
-
use_safetensors=True,
|
12 |
-
trust_remote_code=True,
|
13 |
-
device="cuda:0",
|
14 |
-
use_triton=use_triton,
|
15 |
-
quantize_config=None)
|
16 |
-
|
17 |
-
#creating pipeline
|
18 |
-
pipe = pipeline(
|
19 |
-
"text-generation",
|
20 |
-
model=model,
|
21 |
-
tokenizer=tokenizer,
|
22 |
max_new_tokens=512,
|
23 |
temperature=0.6,
|
24 |
top_p=0.95,
|
25 |
repetition_penalty=1.15
|
26 |
)
|
27 |
|
28 |
-
from langchain.llms import HuggingFacePipeline
|
29 |
-
from langchain.chains import LLMChain
|
30 |
-
from langchain import PromptTemplate
|
31 |
-
|
32 |
-
llm = HuggingFacePipeline(pipeline=pipe)
|
33 |
-
|
34 |
system_message = """
|
35 |
You are a helpful, respectful and honest assistant. Your job is to answer the users query as best as possible given the Web Page Content. Your answers should not include any harmful, unethical, racist, sexist, toxic, dangerous, or illegal content. If you DO NOT KNOW THE ANSWER DO NOT SHARE FALSE INFORMATION.
|
36 |
You have been given scraped text content of a webpage under the section called "Web Page Content". Using this information answer the users query. However, if the webpage DOES NOT contain the answer to the query, you CAN answer based on your existing knowledge IF you are sure of the answer, but ALWAYS let the user know when doing so.
|
37 |
"""
|
38 |
|
39 |
-
|
|
|
40 |
{system_message}
|
41 |
<</SYS>>
|
42 |
|
@@ -47,20 +25,24 @@ Web Page Content:
|
|
47 |
|
48 |
{prompt} [/INST]'''
|
49 |
|
50 |
-
|
51 |
-
chat = LLMChain(
|
52 |
-
llm=llm,
|
53 |
-
prompt=PromptTemplate.from_template(prompt_template),
|
54 |
-
verbose=True
|
55 |
-
)
|
56 |
|
57 |
import requests
|
58 |
from bs4 import BeautifulSoup
|
59 |
import re
|
60 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
61 |
def run(url, input):
|
62 |
context = scraper(url)
|
63 |
-
response =
|
64 |
|
65 |
return response
|
66 |
|
|
|
1 |
+
from ctransformers import AutoModelForCausalLM
|
|
|
2 |
|
3 |
+
model = AutoModelForCausalLM.from_pretrained(
|
4 |
+
model_path_or_repo_id="TheBloke/Llama-2-7B-chat-GGML",
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
5 |
max_new_tokens=512,
|
6 |
temperature=0.6,
|
7 |
top_p=0.95,
|
8 |
repetition_penalty=1.15
|
9 |
)
|
10 |
|
|
|
|
|
|
|
|
|
|
|
|
|
11 |
system_message = """
|
12 |
You are a helpful, respectful and honest assistant. Your job is to answer the users query as best as possible given the Web Page Content. Your answers should not include any harmful, unethical, racist, sexist, toxic, dangerous, or illegal content. If you DO NOT KNOW THE ANSWER DO NOT SHARE FALSE INFORMATION.
|
13 |
You have been given scraped text content of a webpage under the section called "Web Page Content". Using this information answer the users query. However, if the webpage DOES NOT contain the answer to the query, you CAN answer based on your existing knowledge IF you are sure of the answer, but ALWAYS let the user know when doing so.
|
14 |
"""
|
15 |
|
16 |
+
def generate_prompt(system_message, context, prompt):
|
17 |
+
prompt=f'''[INST] <<SYS>>
|
18 |
{system_message}
|
19 |
<</SYS>>
|
20 |
|
|
|
25 |
|
26 |
{prompt} [/INST]'''
|
27 |
|
28 |
+
return prompt
|
|
|
|
|
|
|
|
|
|
|
29 |
|
30 |
import requests
|
31 |
from bs4 import BeautifulSoup
|
32 |
import re
|
33 |
|
34 |
+
def scraper(url):
|
35 |
+
req = requests.get(url)
|
36 |
+
soup = BeautifulSoup(req.content, "html.parser")
|
37 |
+
context = soup.get_text()
|
38 |
+
relevant_text = soup.get_text()
|
39 |
+
cleaned_text = re.sub(r'\s+', ' ', relevant_text).strip()
|
40 |
+
|
41 |
+
return cleaned_text
|
42 |
+
|
43 |
def run(url, input):
|
44 |
context = scraper(url)
|
45 |
+
response = model(generate_prompt(system_message=system_message, context=context, prompt=input))
|
46 |
|
47 |
return response
|
48 |
|