Spaces:
Runtime error
Runtime error
File size: 1,606 Bytes
39dff4c 99914ec 4a0366f c352f02 a147fbd ed0aa7b 24ed9e0 c6ddc86 3661992 4854a72 bb31795 4854a72 af86876 c6ddc86 4854a72 fd6e173 bb31795 4854a72 9dd7ad1 bb31795 ea7a2b9 ca860d3 39dff4c fd6e173 da239a9 7afe812 9ed9d81 af86876 cf7f506 bb31795 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 |
import gradio as gr
import requests
import json
from decouple import Config
config = Config('.env')
def query_vectara(question):
user_message = question
# Read authentication parameters from the .env file
CUSTOMER_ID = config('CUSTOMER_ID')
CORPUS_ID = config('CORPUS_ID')
API_KEY = config('API_KEY')
# Define the data dictionary
data_dict = {
"query": [
{
"query": user_message,
"num_results": 10,
"corpus_key": [
{
"customer_id": CUSTOMER_ID,
"corpus_id": CORPUS_ID
}
]
}
]
}
# Define the headers
api_key_header = {
"customer-id": CUSTOMER_ID,
"x-api-key": API_KEY
}
# Make the API request
response = requests.post(
"https://api.vectara.io/v1/query",
data=json.dumps(data_dict),
verify=True,
headers=api_key_header,
headers={"Content-Type": "application/json"} # Set Content-Type header
)
if response.status_code == 200:
query_data = response.json()
response_message = f"Response from Vectara API: {json.dumps(query_data, indent=2)}"
else:
response_message = f"Error: {response.status_code}"
return response_message
iface = gr.Interface(
fn=query_vectara,
inputs=[gr.Textbox(label="Input Text")],
outputs=gr.Textbox(label="Output Text"),
title="Vectara Chatbot",
description="Ask me anything using the Vectara API!"
)
iface.launch()
|