joao-vectara commited on
Commit
994ec86
·
verified ·
1 Parent(s): 4485574

Upload 4 files

Browse files
Files changed (4) hide show
  1. query.py +36 -0
  2. requirements.txt +9 -0
  3. style.css +39 -0
  4. upload.py +14 -0
query.py ADDED
@@ -0,0 +1,36 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import requests
2
+ import json
3
+
4
+ def query_vectara(question, customer_id, api_key, corpus_key):
5
+ """Queries the uploaded documents in Vectara API v2."""
6
+ url = f"https://api.vectara.io/v2/corpora/{corpus_key}/query"
7
+ headers = {
8
+ "x-api-key": api_key,
9
+ "Accept": "application/json"
10
+ }
11
+
12
+ payload = {
13
+ "query": question,
14
+ "top_k": 5 # Retrieve top 5 relevant results
15
+ }
16
+
17
+ response = requests.get(url, headers=headers, data=json.dumps(payload))
18
+ return response.json()
19
+
20
+ def process_queries(customer_id, api_key, corpus_key):
21
+ """Runs all predefined queries on the uploaded documents."""
22
+ questions = [
23
+ "Based on uploaded documents, what are the top four challenges of the Fintech sector in Saudi Arabia? list them in bullet points.",
24
+ "Based on uploaded documents, who are the top five leading companies in the Fintech sector in Saudi Arabia? list them in bullet points with brief information on each company.",
25
+ "Based on uploaded documents, summarize Saudi Arabia's Fintech Strategy in five key points.",
26
+ "Based on uploaded documents, describe STC Pay, its position in the market, and partners.",
27
+ "Based on uploaded documents, what are the key differences between Fintech in Saudi vs UAE?",
28
+ "Based on uploaded documents, summarize the Payment Services Provider Regulations (PSPR) in five bullet points."
29
+ ]
30
+
31
+ results = {}
32
+ for question in questions:
33
+ response = query_vectara(question, customer_id, api_key, corpus_key)
34
+ results[question] = response
35
+
36
+ return results
requirements.txt ADDED
@@ -0,0 +1,9 @@
 
 
 
 
 
 
 
 
 
 
1
+ omegaconf==2.3.0
2
+ python-dotenv==1.0.1
3
+ streamlit==1.41.1
4
+ streamlit_pills==0.3.0
5
+ streamlit_feedback==0.1.3
6
+ uuid==1.30
7
+ langdetect==1.0.9
8
+ langcodes==3.4.0
9
+ vectara-agentic==0.2.1
style.css ADDED
@@ -0,0 +1,39 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /* Set background color */
2
+ .stApp {
3
+ background-color: #121212;
4
+ color: white;
5
+ }
6
+
7
+ /* Center content */
8
+ .block-container {
9
+ max-width: 600px;
10
+ margin: auto;
11
+ text-align: center;
12
+ }
13
+
14
+ /* Style file uploader */
15
+ .stFileUploader label {
16
+ font-size: 18px;
17
+ font-weight: bold;
18
+ color: white;
19
+ }
20
+
21
+ .stFileUploader div {
22
+ background-color: #292929;
23
+ padding: 20px;
24
+ border-radius: 10px;
25
+ border: 2px dashed #555;
26
+ text-align: center;
27
+ }
28
+
29
+ .stFileUploader button {
30
+ background-color: #444;
31
+ border: 1px solid #777;
32
+ color: white;
33
+ padding: 5px 15px;
34
+ border-radius: 5px;
35
+ }
36
+
37
+ .stFileUploader span {
38
+ color: #ccc;
39
+ }
upload.py ADDED
@@ -0,0 +1,14 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import requests
2
+
3
+ def upload_file_to_vectara(file, customer_id, api_key, corpus_key):
4
+ """Uploads a file to Vectara API v2."""
5
+ url = f"https://api.vectara.io/v2/corpora/{corpus_key}/upload_file"
6
+ headers = {
7
+ "x-api-key": api_key,
8
+ "Accept": "application/json"
9
+ }
10
+
11
+ files = {"file": (file.name, file.getvalue())}
12
+ response = requests.post(url, headers=headers, files=files)
13
+
14
+ return response.json()