JAYASWAROOP commited on
Commit
592ae0e
Β·
verified Β·
1 Parent(s): 05af244

Update src/streamlit_app.py

Browse files
Files changed (1) hide show
  1. src/streamlit_app.py +146 -38
src/streamlit_app.py CHANGED
@@ -1,40 +1,148 @@
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
+ from utils import run_agent_sync
3
 
4
+ st.set_page_config(page_title="MCP POC", page_icon="πŸ€–", layout="wide")
5
+
6
+ st.title("Model Context Protocol(MCP) - Learning Path Generator")
7
+
8
+ # Initialize session state for progress
9
+ if 'current_step' not in st.session_state:
10
+ st.session_state.current_step = ""
11
+ if 'progress' not in st.session_state:
12
+ st.session_state.progress = 0
13
+ if 'last_section' not in st.session_state:
14
+ st.session_state.last_section = ""
15
+ if 'is_generating' not in st.session_state:
16
+ st.session_state.is_generating = False
17
+
18
+ # Sidebar for API and URL configuration
19
+ st.sidebar.header("Configuration")
20
+
21
+ # API Key input
22
+ google_api_key = st.sidebar.text_input("Google API Key", type="password")
23
+
24
+ # Pipedream URLs
25
+ st.sidebar.subheader("Pipedream URLs")
26
+ youtube_pipedream_url = st.sidebar.text_input("YouTube URL (Required)",
27
+ placeholder="Enter your Pipedream YouTube URL")
28
+
29
+ # Secondary tool selection
30
+ secondary_tool = st.sidebar.radio(
31
+ "Select Secondary Tool:",
32
+ ["Drive", "Notion"]
33
+ )
34
+
35
+ # Secondary tool URL input
36
+ if secondary_tool == "Drive":
37
+ drive_pipedream_url = st.sidebar.text_input("Drive URL",
38
+ placeholder="Enter your Pipedream Drive URL")
39
+ notion_pipedream_url = None
40
+ else:
41
+ notion_pipedream_url = st.sidebar.text_input("Notion URL",
42
+ placeholder="Enter your Pipedream Notion URL")
43
+ drive_pipedream_url = None
44
+
45
+ # Quick guide before goal input
46
+ st.info("""
47
+ **Quick Guide:**
48
+ 1. Enter your Google API key and YouTube URL (required)
49
+ 2. Select and configure your secondary tool (Drive or Notion)
50
+ 3. Enter a clear learning goal, for example:
51
+ - "I want to learn python basics in 3 days"
52
+ - "I want to learn data science basics in 10 days"
53
+ """)
54
+
55
+ # Main content area
56
+ st.header("Enter Your Goal")
57
+ user_goal = st.text_input("Enter your learning goal:",
58
+ help="Describe what you want to learn, and we'll generate a structured path using YouTube content and your selected tool.")
59
+
60
+ # Progress area
61
+ progress_container = st.container()
62
+ progress_bar = st.empty()
63
+
64
+ def update_progress(message: str):
65
+ """Update progress in the Streamlit UI"""
66
+ st.session_state.current_step = message
67
+
68
+ # Determine section and update progress
69
+ if "Setting up agent with tools" in message:
70
+ section = "Setup"
71
+ st.session_state.progress = 0.1
72
+ elif "Added Google Drive integration" in message or "Added Notion integration" in message:
73
+ section = "Integration"
74
+ st.session_state.progress = 0.2
75
+ elif "Creating AI agent" in message:
76
+ section = "Setup"
77
+ st.session_state.progress = 0.3
78
+ elif "Generating your learning path" in message:
79
+ section = "Generation"
80
+ st.session_state.progress = 0.5
81
+ elif "Learning path generation complete" in message:
82
+ section = "Complete"
83
+ st.session_state.progress = 1.0
84
+ st.session_state.is_generating = False
85
+ else:
86
+ section = st.session_state.last_section or "Progress"
87
+
88
+ st.session_state.last_section = section
89
+
90
+ # Show progress bar
91
+ progress_bar.progress(st.session_state.progress)
92
+
93
+ # Update progress container with current status
94
+ with progress_container:
95
+ # Show section header if it changed
96
+ if section != st.session_state.last_section and section != "Complete":
97
+ st.write(f"**{section}**")
98
+
99
+ # Show message with tick for completed steps
100
+ if message == "Learning path generation complete!":
101
+ st.success("All steps completed! πŸŽ‰")
102
+ else:
103
+ prefix = "βœ“" if st.session_state.progress >= 0.5 else "β†’"
104
+ st.write(f"{prefix} {message}")
105
+
106
+ # Generate Learning Path button
107
+ if st.button("Generate Learning Path", type="primary", disabled=st.session_state.is_generating):
108
+ if not google_api_key:
109
+ st.error("Please enter your Google API key in the sidebar.")
110
+ elif not youtube_pipedream_url:
111
+ st.error("YouTube URL is required. Please enter your Pipedream YouTube URL in the sidebar.")
112
+ elif (secondary_tool == "Drive" and not drive_pipedream_url) or (secondary_tool == "Notion" and not notion_pipedream_url):
113
+ st.error(f"Please enter your Pipedream {secondary_tool} URL in the sidebar.")
114
+ elif not user_goal:
115
+ st.warning("Please enter your learning goal.")
116
+ else:
117
+ try:
118
+ # Set generating flag
119
+ st.session_state.is_generating = True
120
+
121
+ # Reset progress
122
+ st.session_state.current_step = ""
123
+ st.session_state.progress = 0
124
+ st.session_state.last_section = ""
125
+
126
+ result = run_agent_sync(
127
+ google_api_key=google_api_key,
128
+ youtube_pipedream_url=youtube_pipedream_url,
129
+ drive_pipedream_url=drive_pipedream_url,
130
+ notion_pipedream_url=notion_pipedream_url,
131
+ user_goal=user_goal,
132
+ progress_callback=update_progress
133
+ )
134
+
135
+ # Display results
136
+ st.header("Your Learning Path")
137
+ # print(result)
138
+ if result and "messages" in result:
139
+ for msg in result["messages"]:
140
+ st.markdown(f"πŸ“š {msg.content}")
141
+
142
+ else:
143
+ st.error("No results were generated. Please try again.")
144
+ st.session_state.is_generating = False
145
+ except Exception as e:
146
+ st.error(f"An error occurred: {str(e)}")
147
+ st.error("Please check your API keys and URLs, and try again.")
148
+ st.session_state.is_generating = False