Team Ai
Apppublic

pascal-maker/luminus

sourceHugging Faceupdated 2y agoView on Hugging Face
0likes
main.py66 linesDownload Raw Back to root
1import requests2import json3import streamlit as st4 5import requests6from dotenv import load_dotenv7import os8 9load_dotenv()10 11BASE_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.environ.get("APP_TOKEN")15ENDPOINT = "customer" # The endpoint name of the flow16 17 18# You can tweak the flow by adding a tweaks dictionary19# e.g {"OpenAI-XXXXX": {"model_name": "gpt-4"}}20 21 22def run_flow(message: str) -> dict:23    """24    Run a flow with a given message and optional tweaks.25 26    :param message: The message to send to the flow27    :param endpoint: The ID or the endpoint name of the flow28    :param tweaks: Optional tweaks to customize the flow29    :return: The JSON response from the flow30    """31    api_url = f"{BASE_API_URL}/lf/{LANGFLOW_ID}/api/v1/run/{ENDPOINT}"32 33    payload = {34        "input_value": message,35        "output_type": "chat",36        "input_type": "chat",37    }38    39    headers = {"Authorization": "Bearer " + APPLICATION_TOKEN, "Content-Type": "application/json"}40    response = requests.post(api_url, json=payload, headers=headers)41    return response.json()42 43def main():44    st.title("Luminus bot")45    46    message = st.text_area("Message", placeholder="Ask something...")47    48    if st.button("Run Flow"):49        if not message.strip():50            st.error("Please enter a message")51            return52    53        try:54            with st.spinner("Running flow..."):55                response = run_flow(message)56            57            response = response["outputs"][0]["outputs"][0]["results"]["message"]["text"]58            st.markdown(response)59        except Exception as e:60            st.error(str(e))61 62if __name__ == "__main__":63    main()64 65 66