import streamlit as st import os from langserve.client import RemoteRunnable from httpx import HTTPStatusError from dotenv import load_dotenv # Load the environment variable load_dotenv() # Get the API key from environment variables token = os.environ.get("BACK_API_KEY") # Initialize the RemoteRunnable with your API endpoint and headers #rag_app = RemoteRunnable("http://127.0.0.1:8000/rag-chroma/", headers={"x-api-key": f"{token}"}) rag_app = RemoteRunnable("https://rjuro-rag-lex.hf.space/rag-chroma/", headers={"x-api-key": f"{token}"}) # Streamlit app def main(): # Title of the app st.title("Question Answering App") st.write("This app uses the a RAG pipeline on a different space to answer your questions about the Lex and Sam Interview.") st.markdown("You can find the interview [here](https://lexfridman.com/sam-altman-2-transcript/)") # User input question = st.text_input("Type your question here:") # Button to send the question if st.button("Get Answer"): try: # Use the RemoteRunnable to send the question and get the answer answer = rag_app.invoke(question) # Display the answer st.success(answer) except HTTPStatusError as e: # Handle potential errors from the API call st.error(f"Failed to get an answer. Error: {e}") if __name__ == "__main__": main()