mohith96 commited on
Commit
fb56984
·
verified ·
1 Parent(s): 42aa7ed

Update src/streamlit_app.py

Browse files
Files changed (1) hide show
  1. src/streamlit_app.py +17 -3
src/streamlit_app.py CHANGED
@@ -1,5 +1,6 @@
1
  import streamlit as st
2
  import requests
 
3
  import time
4
 
5
  # =============================
@@ -9,6 +10,9 @@ import time
9
  BACKEND_URL = "https://mohith96-researchagentbackend.hf.space/research"
10
  REQUEST_TIMEOUT = 300 # seconds
11
 
 
 
 
12
  # =============================
13
  # PAGE SETUP
14
  # =============================
@@ -54,24 +58,34 @@ with col1:
54
  if run_clicked:
55
  if not query.strip():
56
  st.warning("You need to enter a research query. This is not optional.")
 
 
57
  else:
58
  with st.spinner("Running research pipeline..."):
59
  try:
 
 
 
 
60
  response = requests.post(
61
  BACKEND_URL,
62
  json={"query": query},
 
63
  timeout=REQUEST_TIMEOUT
64
  )
65
 
66
  if response.status_code != 200:
67
- st.error(f"Backend error ({response.status_code}). Check logs.")
 
 
 
68
  else:
69
  payload = response.json()
70
  st.session_state.title = payload.get("title", "Untitled")
71
  st.session_state.result = payload.get("report", "")
72
 
73
  except requests.exceptions.Timeout:
74
- st.error("Backend timed out. Either it's slow or dead.")
75
  except Exception as e:
76
  st.error(f"Unexpected failure: {str(e)}")
77
 
@@ -97,4 +111,4 @@ if st.session_state.result:
97
  # =============================
98
 
99
  st.divider()
100
- st.caption("Frontend-only Space. All intelligence lives in the backend. As it should.")
 
1
  import streamlit as st
2
  import requests
3
+ import os
4
  import time
5
 
6
  # =============================
 
10
  BACKEND_URL = "https://mohith96-researchagentbackend.hf.space/research"
11
  REQUEST_TIMEOUT = 300 # seconds
12
 
13
+ # Hugging Face token for private backend access
14
+ HF_BACKEND_TOKEN = os.getenv("HF_BACKEND_TOKEN")
15
+
16
  # =============================
17
  # PAGE SETUP
18
  # =============================
 
58
  if run_clicked:
59
  if not query.strip():
60
  st.warning("You need to enter a research query. This is not optional.")
61
+ elif not HF_BACKEND_TOKEN:
62
+ st.error("Backend token missing. Set HF_BACKEND_TOKEN in Space secrets.")
63
  else:
64
  with st.spinner("Running research pipeline..."):
65
  try:
66
+ headers = {
67
+ "Authorization": f"Bearer {HF_BACKEND_TOKEN}"
68
+ }
69
+
70
  response = requests.post(
71
  BACKEND_URL,
72
  json={"query": query},
73
+ headers=headers,
74
  timeout=REQUEST_TIMEOUT
75
  )
76
 
77
  if response.status_code != 200:
78
+ st.error(
79
+ f"Backend error ({response.status_code}). "
80
+ f"Response: {response.text}"
81
+ )
82
  else:
83
  payload = response.json()
84
  st.session_state.title = payload.get("title", "Untitled")
85
  st.session_state.result = payload.get("report", "")
86
 
87
  except requests.exceptions.Timeout:
88
+ st.error("Backend timed out. Either it's slow or asleep.")
89
  except Exception as e:
90
  st.error(f"Unexpected failure: {str(e)}")
91
 
 
111
  # =============================
112
 
113
  st.divider()
114
+ st.caption("Frontend-only Space. Backend is private and authenticated. As it should be.")