Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -3,16 +3,19 @@ import requests
|
|
| 3 |
import json
|
| 4 |
|
| 5 |
# Function to interact with Vectara API
|
| 6 |
-
def query_vectara(question):
|
| 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":
|
| 16 |
"start": 0,
|
| 17 |
"numResults": 10,
|
| 18 |
"corpusKey": [
|
|
@@ -53,13 +56,12 @@ def query_vectara(question):
|
|
| 53 |
else:
|
| 54 |
return {"error": "Failed to query Vectara API"}
|
| 55 |
|
| 56 |
-
# Create a Gradio
|
| 57 |
-
iface = gr.
|
| 58 |
fn=query_vectara,
|
| 59 |
-
|
| 60 |
-
|
| 61 |
-
|
| 62 |
-
capture_session=True
|
| 63 |
)
|
| 64 |
|
| 65 |
# Run the Gradio interface
|
|
|
|
| 3 |
import json
|
| 4 |
|
| 5 |
# Function to interact with Vectara API
|
| 6 |
+
def query_vectara(question, chat_history):
|
| 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 |
+
# Get the user's message from the chat history
|
| 13 |
+
user_message = chat_history[-1][0]
|
| 14 |
+
|
| 15 |
query_body = {
|
| 16 |
"query": [
|
| 17 |
{
|
| 18 |
+
"query": user_message, # Use the user's message as the query
|
| 19 |
"start": 0,
|
| 20 |
"numResults": 10,
|
| 21 |
"corpusKey": [
|
|
|
|
| 56 |
else:
|
| 57 |
return {"error": "Failed to query Vectara API"}
|
| 58 |
|
| 59 |
+
# Create a Gradio ChatInterface
|
| 60 |
+
iface = gr.ChatInterface(
|
| 61 |
fn=query_vectara,
|
| 62 |
+
examples=["Hello", "What is the weather today?", "Tell me a joke"],
|
| 63 |
+
title="Vectara Chatbot",
|
| 64 |
+
description="Ask me anything using the Vectara API!",
|
|
|
|
| 65 |
)
|
| 66 |
|
| 67 |
# Run the Gradio interface
|