shubham142000 commited on
Commit
e467151
ยท
verified ยท
1 Parent(s): 33ec1e1

Update src/streamlit_app.py

Browse files
Files changed (1) hide show
  1. src/streamlit_app.py +210 -25
src/streamlit_app.py CHANGED
@@ -1,3 +1,164 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  import os
2
  import json
3
  import streamlit as st
@@ -19,33 +180,59 @@ client = Together(api_key=TOGETHER_API_KEY)
19
  # -------------------#
20
  st.set_page_config(page_title="FutureScope: Research Direction Explorer", layout="wide")
21
 
22
- st.markdown("""
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
23
  <style>
24
- body {
25
- background: linear-gradient(135deg, #0f2027, #203a43, #2c5364);
26
- color: #FFFFFF;
27
- }
28
- h1, h2, h3 {
29
- text-align: center;
30
- color: #FFD700;
31
  font-family: 'Poppins', sans-serif;
32
- }
33
- .footer {
 
 
 
 
34
  position: fixed;
35
  left: 0;
36
  bottom: 0;
37
  width: 100%;
38
- color: white;
39
  text-align: center;
40
  padding: 10px;
41
- background-color: rgba(0,0,0,0.4);
42
- }
43
- .stButton > button {
44
- background-color: #FFD700 !important;
45
  color: black !important;
46
  font-weight: bold;
47
  border-radius: 10px;
48
- }
 
 
 
49
  </style>
50
  """, unsafe_allow_html=True)
51
 
@@ -96,13 +283,10 @@ if st.button("Generate Research Insights"):
96
  # JSON Cleaning & Parsing
97
  # -------------------#
98
  def extract_json(text):
99
- """Extract valid JSON portion from the model response."""
100
  text = text.strip()
101
- text = re.sub(r"^```json|```$", "", text).strip() # remove code fences
102
  match = re.search(r'\{.*\}', text, re.DOTALL)
103
- if match:
104
- return match.group(0)
105
- return text
106
 
107
  cleaned = extract_json(raw_content)
108
  try:
@@ -116,7 +300,7 @@ if st.button("Generate Research Insights"):
116
  # Display Results
117
  # -------------------#
118
  st.markdown("## ๐Ÿงฉ Evolution Summary")
119
- st.markdown(f"<div style='background:#1e2a38;padding:15px;border-radius:10px;'>{data['evolution_summary']}</div>", unsafe_allow_html=True)
120
 
121
  # Timeline Chart
122
  if "timeline" in data and len(data["timeline"]) > 0:
@@ -125,7 +309,7 @@ if st.button("Generate Research Insights"):
125
  fig = px.scatter(df, x="year", y="trend", title="๐Ÿ“ˆ Topic Evolution Over Time",
126
  size=[10]*len(df), text="trend", color_discrete_sequence=["gold"])
127
  fig.update_traces(textposition='top center', marker=dict(symbol="circle"))
128
- fig.update_layout(template="plotly_dark", height=500)
129
  st.plotly_chart(fig, use_container_width=True)
130
  else:
131
  st.warning("Timeline data invalid โ€” showing raw table:")
@@ -135,7 +319,7 @@ if st.button("Generate Research Insights"):
135
  st.markdown("## ๐Ÿ”ฎ Predicted Future Directions")
136
  for item in data.get("future_directions", []):
137
  st.markdown(f"""
138
- <div style='background:#142733;padding:15px;margin:10px;border-radius:10px;'>
139
  <h4>๐Ÿง  {item['title']}</h4>
140
  <p>{item['reason']}</p>
141
  </div>
@@ -157,4 +341,5 @@ if st.button("Generate Research Insights"):
157
  # -------------------#
158
  # Footer
159
  # -------------------#
160
- st.markdown("<div class='footer'>ยฉ Group 6 ILP TCS Research ", unsafe_allow_html=True)
 
 
1
+ # import os
2
+ # import json
3
+ # import streamlit as st
4
+ # import pandas as pd
5
+ # import plotly.express as px
6
+ # from together import Together
7
+ # from dotenv import load_dotenv
8
+ # import re
9
+
10
+ # # -------------------#
11
+ # # Secure API key load
12
+ # # -------------------#
13
+ # load_dotenv()
14
+ # TOGETHER_API_KEY = os.getenv("TOGETHER_API_KEY", "987adcf573b9658c775b671270aef959b3d38793771932f372f9f2a9ed5b78bf")
15
+ # client = Together(api_key=TOGETHER_API_KEY)
16
+
17
+ # # -------------------#
18
+ # # Streamlit UI setup
19
+ # # -------------------#
20
+ # st.set_page_config(page_title="FutureScope: Research Direction Explorer", layout="wide")
21
+
22
+ # st.markdown("""
23
+ # <style>
24
+ # body {
25
+ # background: linear-gradient(135deg, #0f2027, #203a43, #2c5364);
26
+ # color: #FFFFFF;
27
+ # }
28
+ # h1, h2, h3 {
29
+ # text-align: center;
30
+ # color: #FFD700;
31
+ # font-family: 'Poppins', sans-serif;
32
+ # }
33
+ # .footer {
34
+ # position: fixed;
35
+ # left: 0;
36
+ # bottom: 0;
37
+ # width: 100%;
38
+ # color: white;
39
+ # text-align: center;
40
+ # padding: 10px;
41
+ # background-color: rgba(0,0,0,0.4);
42
+ # }
43
+ # .stButton > button {
44
+ # background-color: #FFD700 !important;
45
+ # color: black !important;
46
+ # font-weight: bold;
47
+ # border-radius: 10px;
48
+ # }
49
+ # </style>
50
+ # """, unsafe_allow_html=True)
51
+
52
+ # # -------------------#
53
+ # # App Title
54
+ # # -------------------#
55
+ # st.markdown("<h1>๐Ÿงญ FutureScope: Research Direction Explorer</h1>", unsafe_allow_html=True)
56
+ # st.markdown("<p style='text-align:center;'>Discover how your research area evolved and where it's heading next ๐Ÿš€</p>", unsafe_allow_html=True)
57
+
58
+ # # -------------------#
59
+ # # User Input
60
+ # # -------------------#
61
+ # user_topic = st.text_input("๐Ÿ” Enter your research topic", placeholder="e.g. Graph Neural Networks for Drug Discovery")
62
+
63
+ # # -------------------#
64
+ # # Main Logic
65
+ # # -------------------#
66
+ # if st.button("Generate Research Insights"):
67
+ # if not user_topic.strip():
68
+ # st.warning("โš ๏ธ Please enter a valid research topic.")
69
+ # else:
70
+ # with st.spinner("Analyzing topic evolution and forecasting future directions... โณ"):
71
+
72
+ # # Prompt Design
73
+ # prompt = f"""
74
+ # You are a world-class AI research assistant specialized in analyzing research trends.
75
+ # Given the topic: "{user_topic}", perform the following:
76
+ # 1. Summarize how this research area has evolved in the past 10โ€“15 years.
77
+ # 2. Identify key milestones and subfields in a timeline format.
78
+ # 3. Predict 3โ€“5 future research directions and explain why each matters.
79
+ # Return the output strictly in JSON format like this:
80
+ # {{
81
+ # "evolution_summary": "...",
82
+ # "timeline": [{{"year": ..., "trend": "..."}}, ...],
83
+ # "future_directions": [{{"title": "...", "reason": "..."}}, ...]
84
+ # }}
85
+ # """
86
+
87
+ # # Call Together API
88
+ # response = client.chat.completions.create(
89
+ # model="meta-llama/Llama-3.3-70B-Instruct-Turbo-Free",
90
+ # messages=[{"role": "user", "content": prompt}]
91
+ # )
92
+
93
+ # raw_content = response.choices[0].message.content
94
+
95
+ # # -------------------#
96
+ # # JSON Cleaning & Parsing
97
+ # # -------------------#
98
+ # def extract_json(text):
99
+ # """Extract valid JSON portion from the model response."""
100
+ # text = text.strip()
101
+ # text = re.sub(r"^```json|```$", "", text).strip() # remove code fences
102
+ # match = re.search(r'\{.*\}', text, re.DOTALL)
103
+ # if match:
104
+ # return match.group(0)
105
+ # return text
106
+
107
+ # cleaned = extract_json(raw_content)
108
+ # try:
109
+ # data = json.loads(cleaned)
110
+ # except Exception as e:
111
+ # st.error(f"โš ๏ธ Failed to parse JSON: {e}")
112
+ # st.text_area("Raw Response", raw_content, height=300)
113
+ # st.stop()
114
+
115
+ # # -------------------#
116
+ # # Display Results
117
+ # # -------------------#
118
+ # st.markdown("## ๐Ÿงฉ Evolution Summary")
119
+ # st.markdown(f"<div style='background:#1e2a38;padding:15px;border-radius:10px;'>{data['evolution_summary']}</div>", unsafe_allow_html=True)
120
+
121
+ # # Timeline Chart
122
+ # if "timeline" in data and len(data["timeline"]) > 0:
123
+ # df = pd.DataFrame(data["timeline"])
124
+ # if "year" in df.columns and "trend" in df.columns:
125
+ # fig = px.scatter(df, x="year", y="trend", title="๐Ÿ“ˆ Topic Evolution Over Time",
126
+ # size=[10]*len(df), text="trend", color_discrete_sequence=["gold"])
127
+ # fig.update_traces(textposition='top center', marker=dict(symbol="circle"))
128
+ # fig.update_layout(template="plotly_dark", height=500)
129
+ # st.plotly_chart(fig, use_container_width=True)
130
+ # else:
131
+ # st.warning("Timeline data invalid โ€” showing raw table:")
132
+ # st.dataframe(df)
133
+
134
+ # # Future Directions
135
+ # st.markdown("## ๐Ÿ”ฎ Predicted Future Directions")
136
+ # for item in data.get("future_directions", []):
137
+ # st.markdown(f"""
138
+ # <div style='background:#142733;padding:15px;margin:10px;border-radius:10px;'>
139
+ # <h4>๐Ÿง  {item['title']}</h4>
140
+ # <p>{item['reason']}</p>
141
+ # </div>
142
+ # """, unsafe_allow_html=True)
143
+
144
+ # # Tools: Copy / Download
145
+ # col1, col2 = st.columns(2)
146
+ # with col1:
147
+ # if st.button("๐Ÿ“‹ Copy Insights"):
148
+ # st.write("Copied to clipboard! (Use Ctrl+C manually to copy)")
149
+ # with col2:
150
+ # st.download_button(
151
+ # label="๐Ÿ’พ Download JSON",
152
+ # data=json.dumps(data, indent=2),
153
+ # file_name=f"{user_topic.replace(' ','_')}_future_directions.json",
154
+ # mime="application/json"
155
+ # )
156
+
157
+ # # -------------------#
158
+ # # Footer
159
+ # # -------------------#
160
+ # st.markdown("<div class='footer'>ยฉ Group 6 ILP TCS Research ", unsafe_allow_html=True)
161
+
162
  import os
163
  import json
164
  import streamlit as st
 
180
  # -------------------#
181
  st.set_page_config(page_title="FutureScope: Research Direction Explorer", layout="wide")
182
 
183
+ # Detect Streamlit theme
184
+ try:
185
+ theme = st.get_option("theme.base")
186
+ except:
187
+ theme = "dark"
188
+
189
+ # Define theme colors
190
+ if theme == "light":
191
+ BACKGROUND_GRADIENT = "linear-gradient(135deg, #f9f9f9, #eaeaea, #dddddd)"
192
+ TEXT_COLOR = "#000000"
193
+ TITLE_COLOR = "#DAA520"
194
+ CARD_BG = "#ffffff"
195
+ FOOTER_BG = "rgba(0, 0, 0, 0.1)"
196
+ else:
197
+ BACKGROUND_GRADIENT = "linear-gradient(135deg, #0f2027, #203a43, #2c5364)"
198
+ TEXT_COLOR = "#FFFFFF"
199
+ TITLE_COLOR = "#FFD700"
200
+ CARD_BG = "#1e2a38"
201
+ FOOTER_BG = "rgba(0, 0, 0, 0.4)"
202
+
203
+ # -------------------#
204
+ # Dynamic CSS Styling
205
+ # -------------------#
206
+ st.markdown(f"""
207
  <style>
208
+ body {{
209
+ background: {BACKGROUND_GRADIENT};
210
+ color: {TEXT_COLOR};
 
 
 
 
211
  font-family: 'Poppins', sans-serif;
212
+ }}
213
+ h1, h2, h3 {{
214
+ text-align: center;
215
+ color: {TITLE_COLOR};
216
+ }}
217
+ .footer {{
218
  position: fixed;
219
  left: 0;
220
  bottom: 0;
221
  width: 100%;
222
+ color: {TEXT_COLOR};
223
  text-align: center;
224
  padding: 10px;
225
+ background-color: {FOOTER_BG};
226
+ }}
227
+ .stButton > button {{
228
+ background-color: {TITLE_COLOR} !important;
229
  color: black !important;
230
  font-weight: bold;
231
  border-radius: 10px;
232
+ }}
233
+ div[data-testid="stMarkdownContainer"] p {{
234
+ color: {TEXT_COLOR};
235
+ }}
236
  </style>
237
  """, unsafe_allow_html=True)
238
 
 
283
  # JSON Cleaning & Parsing
284
  # -------------------#
285
  def extract_json(text):
 
286
  text = text.strip()
287
+ text = re.sub(r"^```json|```$", "", text).strip()
288
  match = re.search(r'\{.*\}', text, re.DOTALL)
289
+ return match.group(0) if match else text
 
 
290
 
291
  cleaned = extract_json(raw_content)
292
  try:
 
300
  # Display Results
301
  # -------------------#
302
  st.markdown("## ๐Ÿงฉ Evolution Summary")
303
+ st.markdown(f"<div style='background:{CARD_BG};padding:15px;border-radius:10px;color:{TEXT_COLOR};'>{data['evolution_summary']}</div>", unsafe_allow_html=True)
304
 
305
  # Timeline Chart
306
  if "timeline" in data and len(data["timeline"]) > 0:
 
309
  fig = px.scatter(df, x="year", y="trend", title="๐Ÿ“ˆ Topic Evolution Over Time",
310
  size=[10]*len(df), text="trend", color_discrete_sequence=["gold"])
311
  fig.update_traces(textposition='top center', marker=dict(symbol="circle"))
312
+ fig.update_layout(template="plotly_dark" if theme == "dark" else "plotly_white", height=500)
313
  st.plotly_chart(fig, use_container_width=True)
314
  else:
315
  st.warning("Timeline data invalid โ€” showing raw table:")
 
319
  st.markdown("## ๐Ÿ”ฎ Predicted Future Directions")
320
  for item in data.get("future_directions", []):
321
  st.markdown(f"""
322
+ <div style='background:{CARD_BG};padding:15px;margin:10px;border-radius:10px;color:{TEXT_COLOR};'>
323
  <h4>๐Ÿง  {item['title']}</h4>
324
  <p>{item['reason']}</p>
325
  </div>
 
341
  # -------------------#
342
  # Footer
343
  # -------------------#
344
+ st.markdown(f"<div class='footer'>ยฉ Group 6 ILP TCS Research</div>", unsafe_allow_html=True)
345
+