File size: 1,522 Bytes
e4e60ab
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
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