Spaces:
Runtime error
Runtime error
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 query URL | |
query_url = f"https://api.vectara.io:443/v1/query" | |
headers = { | |
"x-api-key": api_key, # Use the x-api-key header for authentication | |
} | |
query_body = { | |
"query": user_message, | |
"num_results": 10 | |
} | |
query_response = requests.post(query_url, json=query_body, headers=headers) | |
if query_response.status_code == 200: | |
query_data = query_response.json() | |
response_message = f"Response from Vectara API: {json.dumps(query_data, indent=2)}" | |
else: | |
response_message = f"Error: {query_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() | |