RJuro commited on
Commit
fcf2487
1 Parent(s): 334b1f5
Files changed (1) hide show
  1. app.py +38 -0
app.py ADDED
@@ -0,0 +1,38 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ import os
3
+ from langserve.client import RemoteRunnable
4
+ from httpx import HTTPStatusError
5
+ from dotenv import load_dotenv
6
+
7
+ # Load the environment variable
8
+ load_dotenv()
9
+
10
+ # Get the API key from environment variables
11
+ token = os.environ.get("BACK_API_KEY")
12
+
13
+ # Initialize the RemoteRunnable with your API endpoint and headers
14
+ #rag_app = RemoteRunnable("http://127.0.0.1:8000/rag-chroma/", headers={"x-api-key": f"{token}"})
15
+ rag_app = RemoteRunnable("https://rjuro-rag-lex.hf.space/rag-chroma/", headers={"x-api-key": f"{token}"})
16
+
17
+ # Streamlit app
18
+ def main():
19
+ # Title of the app
20
+ st.title("Question Answering App")
21
+ st.write("This app uses the a RAG pipeline on a different space to answer your questions about the Lex and Sam Interview.")
22
+ st.markdown("You can find the interview [here](https://lexfridman.com/sam-altman-2-transcript/)")
23
+ # User input
24
+ question = st.text_input("Type your question here:")
25
+
26
+ # Button to send the question
27
+ if st.button("Get Answer"):
28
+ try:
29
+ # Use the RemoteRunnable to send the question and get the answer
30
+ answer = rag_app.invoke(question)
31
+ # Display the answer
32
+ st.success(answer)
33
+ except HTTPStatusError as e:
34
+ # Handle potential errors from the API call
35
+ st.error(f"Failed to get an answer. Error: {e}")
36
+
37
+ if __name__ == "__main__":
38
+ main()