Spaces:
Runtime error
Runtime error
File size: 1,803 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 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 |
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()
|