Tonic commited on
Commit
39dff4c
1 Parent(s): 3191e5c

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +66 -0
app.py ADDED
@@ -0,0 +1,66 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ import requests
3
+ import json
4
+
5
+ # Function to interact with Vectara API
6
+ def query_vectara(query_str):
7
+ api_endpoint = "https://api.vectara.io/v1/query"
8
+ customer_id = "<YOUR-CUSTOMER-ID>"
9
+ corpus_id = "<YOUR-CORPUS-ID>"
10
+ api_key = "<YOUR-API-KEY>"
11
+
12
+ query_body = {
13
+ "query": [
14
+ {
15
+ "query": query_str,
16
+ "start": 0,
17
+ "numResults": 10,
18
+ "corpusKey": [
19
+ {
20
+ "customerId": customer_id,
21
+ "corpusId": corpus_id,
22
+ "lexicalInterpolationConfig": {"lambda": 0.025}
23
+ }
24
+ ],
25
+ "contextConfig": {
26
+ "sentencesBefore": 3,
27
+ "sentencesAfter": 3,
28
+ "startTag": "%START_TAG%",
29
+ "endTag": "%END_TAG%"
30
+ },
31
+ "summary": [
32
+ {
33
+ "responseLang": "eng",
34
+ "maxSummarizedResults": 7,
35
+ "summarizerPromptName": "vectara-summarizer-ext-v1.3.0"
36
+ }
37
+ ]
38
+ }
39
+ ]
40
+ }
41
+
42
+ post_headers = {
43
+ "Content-type": "application/json",
44
+ "Accept": "application/json",
45
+ "customer-id": customer_id,
46
+ "x-api-key": api_key
47
+ }
48
+
49
+ response = requests.post(api_endpoint, json=query_body, headers=post_headers)
50
+
51
+ if response.status_code == 200:
52
+ return response.json()
53
+ else:
54
+ return {"error": "Failed to query Vectara API"}
55
+
56
+ # Create a Gradio interface
57
+ iface = gr.Interface(
58
+ fn=query_vectara,
59
+ inputs=gr.inputs.Textbox(text="Ask a question:"),
60
+ outputs=gr.outputs.JSON(),
61
+ live=True,
62
+ capture_session=True
63
+ )
64
+
65
+ # Run the Gradio interface
66
+ iface.launch()