ambrosfitz commited on
Commit
e7baaa3
·
verified ·
1 Parent(s): 0226540

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +13 -26
app.py CHANGED
@@ -5,36 +5,23 @@ import json
5
  API_URL = "https://sendthat.cc"
6
 
7
  def list_indexes():
8
- try:
9
- url = f"{API_URL}/list_indexes"
10
- response = requests.get(url)
11
- response.raise_for_status() # Raise an exception for bad status codes
12
- return response.json()
13
- except requests.exceptions.RequestException as e:
14
- print(f"Error fetching indexes: {e}")
15
- return [] # Return an empty list if there's an error
16
 
17
  def search_document(index_name, query, k):
18
- try:
19
- url = f"{API_URL}/search/{index_name}"
20
- payload = {"text": query, "k": k}
21
- headers = {"Content-Type": "application/json"}
22
- response = requests.post(url, json=payload, headers=headers)
23
- response.raise_for_status()
24
- return response.json(), "", k
25
- except requests.exceptions.RequestException as e:
26
- return {"error": str(e)}, "", k
27
 
28
  def qa_document(index_name, question, k):
29
- try:
30
- url = f"{API_URL}/qa/{index_name}"
31
- payload = {"text": question, "k": k}
32
- headers = {"Content-Type": "application/json"}
33
- response = requests.post(url, json=payload, headers=headers)
34
- response.raise_for_status()
35
- return response.json(), "", k
36
- except requests.exceptions.RequestException as e:
37
- return {"error": str(e)}, "", k
38
 
39
  def refresh_indexes():
40
  indexes = list_indexes()
 
5
  API_URL = "https://sendthat.cc"
6
 
7
  def list_indexes():
8
+ url = f"{API_URL}/list_indexes"
9
+ response = requests.get(url)
10
+ return response.json()
 
 
 
 
 
11
 
12
  def search_document(index_name, query, k):
13
+ url = f"{API_URL}/search/{index_name}"
14
+ payload = {"text": query, "k": k}
15
+ headers = {"Content-Type": "application/json"}
16
+ response = requests.post(url, json=payload, headers=headers)
17
+ return response.json(), "", k # Return empty string to clear input
 
 
 
 
18
 
19
  def qa_document(index_name, question, k):
20
+ url = f"{API_URL}/qa/{index_name}"
21
+ payload = {"text": question, "k": k}
22
+ headers = {"Content-Type": "application/json"}
23
+ response = requests.post(url, json=payload, headers=headers)
24
+ return response.json(), "", k # Return empty string to clear input
 
 
 
 
25
 
26
  def refresh_indexes():
27
  indexes = list_indexes()