Spaces:
Runtime error
Runtime error
import requests | |
import json | |
import streamlit as st | |
import requests | |
from dotenv import load_dotenv | |
import os | |
load_dotenv() | |
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.environ.get("APP_TOKEN") | |
ENDPOINT = "customer" # The endpoint name of the flow | |
# You can tweak the flow by adding a tweaks dictionary | |
# e.g {"OpenAI-XXXXX": {"model_name": "gpt-4"}} | |
def run_flow(message: str) -> dict: | |
""" | |
Run a flow with a given message and optional tweaks. | |
:param message: The message to send to the flow | |
:param endpoint: The ID or the endpoint name of the flow | |
:param tweaks: Optional tweaks to customize the flow | |
:return: The JSON response from the flow | |
""" | |
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"} | |
response = requests.post(api_url, json=payload, headers=headers) | |
return response.json() | |
def main(): | |
st.title("Luminus bot") | |
message = st.text_area("Message", placeholder="Ask something...") | |
if st.button("Run Flow"): | |
if not message.strip(): | |
st.error("Please enter a message") | |
return | |
try: | |
with st.spinner("Running flow..."): | |
response = run_flow(message) | |
response = response["outputs"][0]["outputs"][0]["results"]["message"]["text"] | |
st.markdown(response) | |
except Exception as e: | |
st.error(str(e)) | |
if __name__ == "__main__": | |
main() | |