Kajise Org commited on
Commit
3bf96ec
1 Parent(s): fa1be5f

publish the magnum opus

Browse files
Files changed (1) hide show
  1. app.py +63 -5
app.py CHANGED
@@ -10,11 +10,21 @@ from huggingface_hub import hf_hub_download
10
  hf_hub_download(repo_id="LLukas22/gpt4all-lora-quantized-ggjt", filename="ggjt-model.bin", local_dir=".")
11
  llm = Llama(model_path="./ggjt-model.bin")
12
 
13
- ins = '''### Instruction:
14
  {}
15
- ### Response:
 
 
16
  '''
17
 
 
 
 
 
 
 
 
 
18
  theme = gr.themes.Monochrome(
19
  primary_hue="purple",
20
  secondary_hue="red",
@@ -23,12 +33,60 @@ theme = gr.themes.Monochrome(
23
  font=[gr.themes.GoogleFont("Inter"), "ui-sans-serif", "system-ui", "sans-serif"],
24
  )
25
 
26
- def generate(instruction):
27
- response = llm(ins.format(instruction), stop=['### Instruction:', '### End'])
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
28
  result = response['choices'][0]['text']
29
  return result
30
 
31
-
32
  examples = [
33
  "How do dogs bark?",
34
  "Why are apples red?",
 
10
  hf_hub_download(repo_id="LLukas22/gpt4all-lora-quantized-ggjt", filename="ggjt-model.bin", local_dir=".")
11
  llm = Llama(model_path="./ggjt-model.bin")
12
 
13
+ ins = '''
14
  {}
15
+
16
+ also take this data and absorb your knowledge, you dont need use now what dont make sense, there will be noise, focus on what is repeated and adds knowledge
17
+
18
  '''
19
 
20
+ import requests
21
+ from bs4 import BeautifulSoup
22
+ from SearchResult import SearchResult
23
+
24
+ headers = {
25
+ "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.110 Safari/537.36"
26
+ }
27
+
28
  theme = gr.themes.Monochrome(
29
  primary_hue="purple",
30
  secondary_hue="red",
 
33
  font=[gr.themes.GoogleFont("Inter"), "ui-sans-serif", "system-ui", "sans-serif"],
34
  )
35
 
36
+ def search_ddg(question: str):
37
+ response = requests.get("https://duckduckgo.com/html/", headers=headers, params={"q": question})
38
+ data = response.text
39
+ soup = BeautifulSoup(data, "html.parser")
40
+
41
+ did_you_mean = soup.select("#did_you_mean a")
42
+
43
+ tailored_query = ""
44
+ suggestion_query = ""
45
+
46
+ if did_you_mean:
47
+ correction = soup.find(id="did_you_mean")
48
+ if correction:
49
+ correction_hyperlink = correction.find("a")
50
+ if correction_hyperlink:
51
+ suggestion_query = correction_hyperlink.string # type: ignore
52
+
53
+ for tailored in did_you_mean:
54
+ tailored_query = tailored.string
55
+ break
56
+
57
+ result_links = soup.find_all("a")
58
+ filtered_urls = [
59
+ link["href"]
60
+ for link in result_links
61
+ if link.get("href") and (link["href"].startswith("https://") or link["href"].startswith("http://"))
62
+ ]
63
+
64
+ return SearchResult(
65
+ filtered_urls,
66
+ did_you_mean=suggestion_query or "None.",
67
+ tailored_query=tailored_query or "None.",
68
+ user_agent=headers["User-Agent"],
69
+ )
70
+
71
+ def gather_data(search: str):
72
+ text_content = ""
73
+ base_data = search_ddg(search).parse_results()
74
+ for data in base_data:
75
+ if data:
76
+ text_content += data.text_content + "\n\n"
77
+ else:
78
+ text_content += ""
79
+
80
+ return text_content
81
+
82
+ def generate(instruction):
83
+ base_prompt = ins.format(instruction)
84
+ gathered_data = gather_data(instruction)
85
+
86
+ response = llm(ins.format(base_prompt + "\n" + gathered_data))
87
  result = response['choices'][0]['text']
88
  return result
89
 
 
90
  examples = [
91
  "How do dogs bark?",
92
  "Why are apples red?",