Spaces:
Runtime error
Runtime error
import requests | |
import json | |
import gradio as gr | |
from dotenv import load_dotenv | |
import os | |
# Load environment variables | |
load_dotenv() | |
# Configuration variables | |
BASE_API_URL = "https://api.langflow.astra.datastax.com" | |
LANGFLOW_ID = "01375dcf-c094-4a69-9370-bc9c86149df0" | |
FLOW_ID = "c6fc7602-e2c5-4881-b758-404759b7c65f" | |
APPLICATION_TOKEN = os.getenv("APP_TOKEN") | |
ENDPOINT = "customer" # The endpoint name of the flow | |
# Function to run the flow | |
def run_flow(message: str) -> str: | |
api_url = f"{BASE_API_URL}/lf/{LANGFLOW_ID}/api/v1/run/{ENDPOINT}" | |
payload = { | |
"input_value": message, | |
"output_type": "chat", | |
"input_type": "chat", | |
} | |
headers = { | |
"Authorization": "Bearer " + APPLICATION_TOKEN, | |
"Content-Type": "application/json" | |
} | |
try: | |
response = requests.post(api_url, json=payload, headers=headers) | |
response_data = response.json() | |
bot_response = response_data["outputs"][0]["outputs"][0]["results"]["message"]["text"] | |
return bot_response | |
except Exception as e: | |
return f"An error occurred: {str(e)}" | |
# Gradio interface | |
interface = gr.Interface( | |
fn=run_flow, | |
inputs=gr.Textbox(label="Message", placeholder="Ask something..."), | |
outputs=gr.Textbox(label="Response"), | |
title="Luminus Bot", | |
description="Ask the Luminus Bot any question and receive assistance." | |
) | |
# Launch the interface with share=True | |
if __name__ == "__main__": | |
interface.launch(share=True) # Generates a public, shareable link | |