sourize commited on
Commit
13eba5e
·
1 Parent(s): 374109e

Added Files

Browse files
Files changed (3) hide show
  1. .streamlit/secrets.toml +8 -0
  2. app.py +57 -0
  3. requirements.txt +3 -0
.streamlit/secrets.toml ADDED
@@ -0,0 +1,8 @@
 
 
 
 
 
 
 
 
 
1
+ # .streamlit/secrets.toml
2
+
3
+ # Your FastAPI backend (if you host it separately, e.g. on Railway or Render)
4
+ backend_url = "https://rag-pathway.onrender.com"
5
+
6
+ # Supabase credentials (if you call Supabase directly from Streamlit)
7
+ SUPABASE_URL = "https://iddmmovzjstbinuptpit.supabase.co"
8
+ SUPABASE_KEY = "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJzdXBhYmFzZSIsInJlZiI6ImlkZG1tb3Z6anN0YmludXB0cGl0Iiwicm9sZSI6InNlcnZpY2Vfcm9sZSIsImlhdCI6MTc0MzQxMDgxMSwiZXhwIjoyMDU4OTg2ODExfQ.MQUoU3JhDSWofJ7Z3zmytbKVF8DOJ9yLBYraDI_YIFw"
app.py ADDED
@@ -0,0 +1,57 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ import requests
3
+
4
+ st.set_page_config(page_title="RagBot", layout="wide")
5
+
6
+ # --- Sidebar: Upload files ---
7
+ st.sidebar.header("📂 Upload Documents")
8
+ uploaded = st.sidebar.file_uploader(
9
+ "Choose PDF/TXT files",
10
+ type=["pdf", "txt"],
11
+ accept_multiple_files=True
12
+ )
13
+
14
+ if uploaded:
15
+ # Show a little notification
16
+ with st.spinner("Uploading and re-indexing…"):
17
+ for f in uploaded:
18
+ files = {"file": (f.name, f.getvalue())}
19
+ res = requests.post(
20
+ f"{st.secrets.backend_url}/upload",
21
+ files=files
22
+ )
23
+ res.raise_for_status()
24
+ # kick off reindex
25
+ requests.post(f"{st.secrets.backend_url}/reindex")
26
+ st.sidebar.success(f"Uploaded {len(uploaded)} file(s) and reindexed.")
27
+
28
+ # --- Main chat interface ---
29
+ st.title("🤖 RagBot")
30
+
31
+ # keep chat history in session state
32
+ if "history" not in st.session_state:
33
+ st.session_state.history = []
34
+
35
+ # show previous messages
36
+ for role, text in st.session_state.history:
37
+ align = "→" if role=="user" else "←"
38
+ st.markdown(f"**{align} {role.capitalize()}**: {text}")
39
+
40
+ # input your question
41
+ question = st.text_input("Ask a question about your documents:")
42
+
43
+ if st.button("Send") and question:
44
+ st.session_state.history.append(("user", question))
45
+ with st.spinner("Thinking…"):
46
+ resp = requests.post(
47
+ f"{st.secrets.backend_url}/qa",
48
+ json={"question": question}
49
+ )
50
+ if resp.status_code == 200:
51
+ answer = resp.json().get("answer")
52
+ st.session_state.history.append(("assistant", answer))
53
+ else:
54
+ st.error("Failed to fetch answer.")
55
+
56
+ # auto-scroll to bottom (hack)
57
+ st.write("") # ensures the last message is visible
requirements.txt ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ streamlit
2
+ requests
3
+ python-multipart # to handle uploads if you ever embed FastAPI inside Streamlit