mohith96 commited on
Commit
4bbac91
Β·
verified Β·
1 Parent(s): 9add798

Update src/streamlit_app.py

Browse files
Files changed (1) hide show
  1. src/streamlit_app.py +98 -38
src/streamlit_app.py CHANGED
@@ -1,40 +1,100 @@
1
- import altair as alt
2
- import numpy as np
3
- import pandas as pd
4
  import streamlit as st
 
 
5
 
6
- """
7
- # Welcome to Streamlit!
8
-
9
- Edit `/streamlit_app.py` to customize this app to your heart's desire :heart:.
10
- If you have any questions, checkout our [documentation](https://docs.streamlit.io) and [community
11
- forums](https://discuss.streamlit.io).
12
-
13
- In the meantime, below is an example of what you can do with just a few lines of code:
14
- """
15
-
16
- num_points = st.slider("Number of points in spiral", 1, 10000, 1100)
17
- num_turns = st.slider("Number of turns in spiral", 1, 300, 31)
18
-
19
- indices = np.linspace(0, 1, num_points)
20
- theta = 2 * np.pi * num_turns * indices
21
- radius = indices
22
-
23
- x = radius * np.cos(theta)
24
- y = radius * np.sin(theta)
25
-
26
- df = pd.DataFrame({
27
- "x": x,
28
- "y": y,
29
- "idx": indices,
30
- "rand": np.random.randn(num_points),
31
- })
32
-
33
- st.altair_chart(alt.Chart(df, height=700, width=700)
34
- .mark_point(filled=True)
35
- .encode(
36
- x=alt.X("x", axis=None),
37
- y=alt.Y("y", axis=None),
38
- color=alt.Color("idx", legend=None, scale=alt.Scale()),
39
- size=alt.Size("rand", legend=None, scale=alt.Scale(range=[1, 150])),
40
- ))
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  import streamlit as st
2
+ import requests
3
+ import time
4
 
5
+ # =============================
6
+ # CONFIG
7
+ # =============================
8
+
9
+ BACKEND_URL = "https://YOUR_BACKEND_SPACE_NAME.hf.space/research"
10
+ REQUEST_TIMEOUT = 300 # seconds
11
+
12
+ # =============================
13
+ # PAGE SETUP
14
+ # =============================
15
+
16
+ st.set_page_config(
17
+ page_title="Research Agent",
18
+ page_icon="πŸ“š",
19
+ layout="wide"
20
+ )
21
+
22
+ st.title("πŸ“š Autonomous Research Agent")
23
+ st.caption("Decompose β†’ Search β†’ Filter β†’ Synthesize. No fluff.")
24
+
25
+ # =============================
26
+ # STATE
27
+ # =============================
28
+
29
+ if "result" not in st.session_state:
30
+ st.session_state.result = None
31
+
32
+ if "title" not in st.session_state:
33
+ st.session_state.title = None
34
+
35
+ # =============================
36
+ # INPUT
37
+ # =============================
38
+
39
+ query = st.text_area(
40
+ label="Research Query",
41
+ placeholder="e.g. Compatibility issues between LangChain, Python 3.12, and Groq LLMs",
42
+ height=120
43
+ )
44
+
45
+ col1, col2 = st.columns([1, 5])
46
+
47
+ with col1:
48
+ run_clicked = st.button("πŸš€ Run Research", use_container_width=True)
49
+
50
+ # =============================
51
+ # ACTION
52
+ # =============================
53
+
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
+
78
+ # =============================
79
+ # OUTPUT
80
+ # =============================
81
+
82
+ if st.session_state.result:
83
+ st.divider()
84
+
85
+ st.subheader(st.session_state.title)
86
+ st.markdown(st.session_state.result)
87
+
88
+ st.download_button(
89
+ label="⬇️ Download Markdown",
90
+ data=st.session_state.result,
91
+ file_name=f"{st.session_state.title}.md",
92
+ mime="text/markdown"
93
+ )
94
+
95
+ # =============================
96
+ # FOOTER
97
+ # =============================
98
+
99
+ st.divider()
100
+ st.caption("Frontend-only Space. All intelligence lives in the backend. As it should.")