Team Ai
Apppublic

pascal-maker/luminus

sourceHugging Faceupdated 2y agoView on Hugging Face
0likes
bot.py49 linesDownload Raw Back to root
1import requests2import json3import gradio as gr4from dotenv import load_dotenv5import os6 7# Load environment variables8load_dotenv()9 10# Configuration variables11BASE_API_URL = "https://api.langflow.astra.datastax.com"12LANGFLOW_ID = "01375dcf-c094-4a69-9370-bc9c86149df0"13FLOW_ID = "c6fc7602-e2c5-4881-b758-404759b7c65f"14APPLICATION_TOKEN = os.getenv("APP_TOKEN")15ENDPOINT = "customer"  # The endpoint name of the flow16 17# Function to run the flow18def run_flow(message: str) -> str:19    api_url = f"{BASE_API_URL}/lf/{LANGFLOW_ID}/api/v1/run/{ENDPOINT}"20    payload = {21        "input_value": message,22        "output_type": "chat",23        "input_type": "chat",24    }25    headers = {26        "Authorization": "Bearer " + APPLICATION_TOKEN,27        "Content-Type": "application/json"28    }29    try:30        response = requests.post(api_url, json=payload, headers=headers)31        response_data = response.json()32        bot_response = response_data["outputs"][0]["outputs"][0]["results"]["message"]["text"]33        return bot_response34    except Exception as e:35        return f"An error occurred: {str(e)}"36 37# Gradio interface38interface = gr.Interface(39    fn=run_flow,40    inputs=gr.Textbox(label="Message", placeholder="Ask something..."),41    outputs=gr.Textbox(label="Response"),42    title="Luminus Bot",43    description="Ask the Luminus Bot any question and receive assistance."44)45 46# Launch the interface with share=True47if __name__ == "__main__":48    interface.launch(share=True)  # Generates a public, shareable link49