Spaces:
Sleeping
Sleeping
Update main.py
Browse files
main.py
CHANGED
@@ -17,62 +17,62 @@ class MyEmbeddingFunction(EmbeddingFunction):
|
|
17 |
for i in range(5):
|
18 |
try:
|
19 |
embeddings = []
|
20 |
-
url = "https://api.
|
21 |
-
|
22 |
-
payload =
|
23 |
"inputs": input
|
24 |
-
}
|
25 |
headers = {
|
26 |
-
'
|
27 |
-
'
|
28 |
-
'
|
29 |
-
'
|
30 |
-
'
|
31 |
-
'
|
32 |
-
'
|
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.
|
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.
|
52 |
|
53 |
-
payload =
|
54 |
"inputs": [input]
|
55 |
-
}
|
56 |
headers = {
|
57 |
-
'
|
58 |
-
'
|
59 |
-
'
|
60 |
-
'
|
61 |
-
'
|
62 |
-
'
|
63 |
-
'
|
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.
|
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.
|
88 |
|
89 |
-
payload =
|
90 |
"inputs": [query]
|
91 |
-
}
|
92 |
headers = {
|
93 |
-
'
|
94 |
-
'
|
95 |
-
'
|
96 |
-
'
|
97 |
-
'
|
98 |
-
'
|
99 |
-
'
|
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.
|
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"])
|