File size: 1,084 Bytes
3026887 |
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 |
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}"})
# Streamlit app
def main():
# Title of the app
st.title("Question Answering App")
# 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() |