thejagstudio commited on
Commit
d5b654a
·
verified ·
1 Parent(s): 0b428a2

Update main.py

Browse files
Files changed (1) hide show
  1. main.py +52 -52
main.py CHANGED
@@ -17,62 +17,62 @@ class MyEmbeddingFunction(EmbeddingFunction):
17
  for i in range(5):
18
  try:
19
  embeddings = []
20
- url = "https://api.deepinfra.com/v1/inference/BAAI/bge-large-en-v1.5"
21
-
22
- payload = json.dumps({
23
  "inputs": input
24
- })
25
  headers = {
26
- 'Accept': 'application/json, text/plain, */*',
27
- 'Accept-Language': 'en-US,en;q=0.9,gu;q=0.8,ru;q=0.7,hi;q=0.6',
28
- 'Connection': 'keep-alive',
29
- 'Content-Type': 'application/json',
30
- 'Origin': 'https://deepinfra.com',
31
- 'Referer': 'https://deepinfra.com/',
32
- 'Sec-Fetch-Dest': 'empty',
33
- 'Sec-Fetch-Mode': 'cors',
34
- 'Sec-Fetch-Site': 'same-site',
35
- 'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/127.0.0.0 Safari/537.36',
36
- 'sec-ch-ua': '"Not)A;Brand";v="99", "Google Chrome";v="127", "Chromium";v="127"',
37
  'sec-ch-ua-mobile': '?0',
38
- 'sec-ch-ua-platform': '"Windows"'
 
 
 
 
39
  }
40
 
41
- response = requests.request("POST", url, headers=headers, data=payload)
42
  return response.json()["embeddings"]
43
  except:
44
  pass
45
 
46
  def embed_query(self, input: Documents) -> Embeddings:
47
- print(input)
48
  for i in range(5):
49
  try:
50
  embeddings = []
51
- url = "https://api.deepinfra.com/v1/inference/BAAI/bge-large-en-v1.5"
52
 
53
- payload = json.dumps({
54
  "inputs": [input]
55
- })
56
  headers = {
57
- 'Accept': 'application/json, text/plain, */*',
58
- 'Accept-Language': 'en-US,en;q=0.9,gu;q=0.8,ru;q=0.7,hi;q=0.6',
59
- 'Connection': 'keep-alive',
60
- 'Content-Type': 'application/json',
61
- 'Origin': 'https://deepinfra.com',
62
- 'Referer': 'https://deepinfra.com/',
63
- 'Sec-Fetch-Dest': 'empty',
64
- 'Sec-Fetch-Mode': 'cors',
65
- 'Sec-Fetch-Site': 'same-site',
66
- 'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/127.0.0.0 Safari/537.36',
67
- 'sec-ch-ua': '"Not)A;Brand";v="99", "Google Chrome";v="127", "Chromium";v="127"',
68
  'sec-ch-ua-mobile': '?0',
69
- 'sec-ch-ua-platform': '"Windows"'
 
 
 
 
70
  }
71
 
72
- response = requests.request("POST", url, headers=headers, data=payload)
73
  return response.json()["embeddings"][0]
74
  except:
75
  pass
 
76
  try:
77
  CHROMA_PATH = "chroma"
78
  custom_embeddings = MyEmbeddingFunction()
@@ -84,28 +84,28 @@ except:
84
 
85
 
86
  def embeddingGen(query):
87
- url = "https://api.deepinfra.com/v1/inference/BAAI/bge-large-en-v1.5"
88
 
89
- payload = json.dumps({
90
  "inputs": [query]
91
- })
92
  headers = {
93
- 'Accept': 'application/json, text/plain, */*',
94
- 'Accept-Language': 'en-US,en;q=0.9,gu;q=0.8,ru;q=0.7,hi;q=0.6',
95
- 'Connection': 'keep-alive',
96
- 'Content-Type': 'application/json',
97
- 'Origin': 'https://deepinfra.com',
98
- 'Referer': 'https://deepinfra.com/',
99
- 'Sec-Fetch-Dest': 'empty',
100
- 'Sec-Fetch-Mode': 'cors',
101
- 'Sec-Fetch-Site': 'same-site',
102
- 'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/127.0.0.0 Safari/537.36',
103
- 'sec-ch-ua': '"Not)A;Brand";v="99", "Google Chrome";v="127", "Chromium";v="127"',
104
  'sec-ch-ua-mobile': '?0',
105
- 'sec-ch-ua-platform': '"Windows"'
 
 
 
 
106
  }
107
 
108
- response = requests.request("POST", url, headers=headers, data=payload)
109
  return response.json()
110
 
111
 
@@ -283,8 +283,8 @@ def getContext():
283
  context = "\n\n---\n\n".join([doc.page_content for doc, _score in results])
284
  sources = [doc.metadata.get("id", None) for doc, _score in results]
285
  return jsonify({"context": context, "sources": sources})
286
- except:
287
- return jsonify({"context": [], "sources": []})
288
 
289
 
290
  @app.route("/api/audioGenerate", methods=["POST"])
 
17
  for i in range(5):
18
  try:
19
  embeddings = []
20
+ url = "https://api-inference.huggingface.co/models/BAAI/bge-large-en-v1.5"
21
+
22
+ payload = {
23
  "inputs": input
24
+ }
25
  headers = {
26
+ 'accept': '*/*',
27
+ 'accept-language': 'en-US,en;q=0.9',
28
+ 'content-type': 'application/json',
29
+ 'origin': 'https://huggingface.co',
30
+ 'priority': 'u=1, i',
31
+ 'referer': 'https://huggingface.co/',
32
+ 'sec-ch-ua': '"Google Chrome";v="131", "Chromium";v="131", "Not_A Brand";v="24"',
 
 
 
 
33
  'sec-ch-ua-mobile': '?0',
34
+ 'sec-ch-ua-platform': '"Windows"',
35
+ 'sec-fetch-dest': 'empty',
36
+ 'sec-fetch-mode': 'cors',
37
+ 'sec-fetch-site': 'same-site',
38
+ 'user-agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/131.0.0.0 Safari/537.36',
39
  }
40
 
41
+ response = requests.post(url, headers=headers, json=payload)
42
  return response.json()["embeddings"]
43
  except:
44
  pass
45
 
46
  def embed_query(self, input: Documents) -> Embeddings:
 
47
  for i in range(5):
48
  try:
49
  embeddings = []
50
+ url = "https://api-inference.huggingface.co/models/BAAI/bge-large-en-v1.5"
51
 
52
+ payload = {
53
  "inputs": [input]
54
+ }
55
  headers = {
56
+ 'accept': '*/*',
57
+ 'accept-language': 'en-US,en;q=0.9',
58
+ 'content-type': 'application/json',
59
+ 'origin': 'https://huggingface.co',
60
+ 'priority': 'u=1, i',
61
+ 'referer': 'https://huggingface.co/',
62
+ 'sec-ch-ua': '"Google Chrome";v="131", "Chromium";v="131", "Not_A Brand";v="24"',
 
 
 
 
63
  'sec-ch-ua-mobile': '?0',
64
+ 'sec-ch-ua-platform': '"Windows"',
65
+ 'sec-fetch-dest': 'empty',
66
+ 'sec-fetch-mode': 'cors',
67
+ 'sec-fetch-site': 'same-site',
68
+ 'user-agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/131.0.0.0 Safari/537.36',
69
  }
70
 
71
+ response = requests.post(url, headers=headers, json=payload)
72
  return response.json()["embeddings"][0]
73
  except:
74
  pass
75
+
76
  try:
77
  CHROMA_PATH = "chroma"
78
  custom_embeddings = MyEmbeddingFunction()
 
84
 
85
 
86
  def embeddingGen(query):
87
+ url = "https://api-inference.huggingface.co/models/BAAI/bge-large-en-v1.5"
88
 
89
+ payload = {
90
  "inputs": [query]
91
+ }
92
  headers = {
93
+ 'accept': '*/*',
94
+ 'accept-language': 'en-US,en;q=0.9',
95
+ 'content-type': 'application/json',
96
+ 'origin': 'https://huggingface.co',
97
+ 'priority': 'u=1, i',
98
+ 'referer': 'https://huggingface.co/',
99
+ 'sec-ch-ua': '"Google Chrome";v="131", "Chromium";v="131", "Not_A Brand";v="24"',
 
 
 
 
100
  'sec-ch-ua-mobile': '?0',
101
+ 'sec-ch-ua-platform': '"Windows"',
102
+ 'sec-fetch-dest': 'empty',
103
+ 'sec-fetch-mode': 'cors',
104
+ 'sec-fetch-site': 'same-site',
105
+ 'user-agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/131.0.0.0 Safari/537.36',
106
  }
107
 
108
+ response = requests.post(url, headers=headers, json=payload)
109
  return response.json()
110
 
111
 
 
283
  context = "\n\n---\n\n".join([doc.page_content for doc, _score in results])
284
  sources = [doc.metadata.get("id", None) for doc, _score in results]
285
  return jsonify({"context": context, "sources": sources})
286
+ except Exception as e:
287
+ return jsonify({"context": [], "sources": [],"error":str(e)})
288
 
289
 
290
  @app.route("/api/audioGenerate", methods=["POST"])