Spaces:
Sleeping
Sleeping
Anand Sampat
commited on
Commit
•
cb98498
1
Parent(s):
3d09df9
functionality changes + aesthetics
Browse files
app.py
CHANGED
@@ -19,7 +19,7 @@ async def call_openai_api(sn_api_key, prompt: str) -> Dict:
|
|
19 |
messages=[
|
20 |
{
|
21 |
"role": "system",
|
22 |
-
"content": "You are a knowledge graph generator. Generate detailed answers to questions posed about subconcepts and give an educated response as if you were a professor explaining to a student."
|
23 |
},
|
24 |
{
|
25 |
"role": "user",
|
@@ -67,7 +67,6 @@ def process_concept(sn_api_key, concept, num_subconcepts, progress=gr.Progress()
|
|
67 |
# clean up response
|
68 |
subconcepts = result.strip().split('\n')
|
69 |
subconcepts = list(set([subconcept.strip() for subconcept in subconcepts]))
|
70 |
-
# print(subconcepts)
|
71 |
num_total_subconcepts = len(subconcepts)
|
72 |
|
73 |
progress(0.2, "Preparing subconcepts")
|
@@ -113,7 +112,6 @@ def process_concept(sn_api_key, concept, num_subconcepts, progress=gr.Progress()
|
|
113 |
}
|
114 |
],
|
115 |
)
|
116 |
-
print(response)
|
117 |
intro_summary = response.choices[0].message.content
|
118 |
|
119 |
end_time = time.time()
|
@@ -138,9 +136,9 @@ def process_concept(sn_api_key, concept, num_subconcepts, progress=gr.Progress()
|
|
138 |
new_tabs = []
|
139 |
new_tab_contents = []
|
140 |
for i in range(len(subconcept_markdowns)):
|
141 |
-
new_tabs.append(gr.update(label=f"Lesson {i+1}: {subconcepts[i].title()}", visible=True))
|
142 |
new_tab_contents.append(gr.Markdown(f"{subconcept_markdowns[i]}"))
|
143 |
-
new_tabs.extend([gr.update(visible=False) for _ in range(MAX_SUBCONCEPTS-len(subconcept_markdowns))])
|
144 |
new_tab_contents.extend([gr.update(visible=False) for _ in range(MAX_SUBCONCEPTS-len(subconcept_markdowns))])
|
145 |
|
146 |
return "Process complete!", markdown_intro, *new_tabs, *new_tab_contents
|
@@ -148,28 +146,21 @@ def process_concept(sn_api_key, concept, num_subconcepts, progress=gr.Progress()
|
|
148 |
with gr.Blocks() as demo:
|
149 |
gr.Markdown(
|
150 |
"""
|
151 |
-
|
152 |
-
|
153 |
-
<
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
154 |
""",
|
155 |
-
elem_id="header"
|
156 |
-
)
|
157 |
-
|
158 |
-
gr.Markdown(
|
159 |
-
"""
|
160 |
-
<div style="margin: auto; width: 50%; text-align: left; font-size: 16px">
|
161 |
-
<ol>
|
162 |
-
<li>Navigate to <a href="https://cloud.sambanova.ai">https://cloud.sambanova.ai</a>, login and copy your API Key</li>
|
163 |
-
<li>Paste it in the SambaNova API Key box below</li>
|
164 |
-
<li>Enter a concept you are interested in (e.g. Variational Autoencoders)</li>
|
165 |
-
<li>Choose the number of subconcepts you want to break your lessons into</li>
|
166 |
-
<li>Click 'Generate Lesson Plan'</li>
|
167 |
-
<li>Wait for a few seconds for multiple LLama 3B and 8B calls to finish</li>
|
168 |
-
<li>Read through and enjoy your lesson plans</li>
|
169 |
-
</ol>
|
170 |
-
</div>
|
171 |
-
""",
|
172 |
-
elem_id="instructions"
|
173 |
)
|
174 |
|
175 |
with gr.Column():
|
@@ -182,14 +173,14 @@ with gr.Blocks() as demo:
|
|
182 |
|
183 |
with gr.Column():
|
184 |
progress_output = gr.Textbox(label="Progress", interactive=True)
|
185 |
-
lesson_intro = gr.Markdown(label="Lesson Intro")
|
186 |
|
187 |
tab_contents = []
|
188 |
|
189 |
with gr.Tabs() as tabs:
|
190 |
for i in range(MAX_SUBCONCEPTS): # Initial set of tabs
|
191 |
with gr.Tab(f"Lesson {i+1}", visible=False):
|
192 |
-
exec(f'tab_{i}=gr.Markdown(f"This is content for Lesson {i+1}")')
|
193 |
exec(f'tab_contents.append(tab_{i})')
|
194 |
|
195 |
generate_btn.click(
|
|
|
19 |
messages=[
|
20 |
{
|
21 |
"role": "system",
|
22 |
+
"content": "You are a knowledge graph generator. Generate detailed answers to questions posed about subconcepts and give an educated response as if you were a professor explaining to a student. Where applicable add in code examples to solidify the concept for the student."
|
23 |
},
|
24 |
{
|
25 |
"role": "user",
|
|
|
67 |
# clean up response
|
68 |
subconcepts = result.strip().split('\n')
|
69 |
subconcepts = list(set([subconcept.strip() for subconcept in subconcepts]))
|
|
|
70 |
num_total_subconcepts = len(subconcepts)
|
71 |
|
72 |
progress(0.2, "Preparing subconcepts")
|
|
|
112 |
}
|
113 |
],
|
114 |
)
|
|
|
115 |
intro_summary = response.choices[0].message.content
|
116 |
|
117 |
end_time = time.time()
|
|
|
136 |
new_tabs = []
|
137 |
new_tab_contents = []
|
138 |
for i in range(len(subconcept_markdowns)):
|
139 |
+
new_tabs.append(gr.update(label=f"Lesson {i+1}: {subconcepts[i].title()}", visible=True, render=True))
|
140 |
new_tab_contents.append(gr.Markdown(f"{subconcept_markdowns[i]}"))
|
141 |
+
new_tabs.extend([gr.update(visible=False, render=False) for _ in range(MAX_SUBCONCEPTS-len(subconcept_markdowns))])
|
142 |
new_tab_contents.extend([gr.update(visible=False) for _ in range(MAX_SUBCONCEPTS-len(subconcept_markdowns))])
|
143 |
|
144 |
return "Process complete!", markdown_intro, *new_tabs, *new_tab_contents
|
|
|
146 |
with gr.Blocks() as demo:
|
147 |
gr.Markdown(
|
148 |
"""
|
149 |
+
# Lesson Plan Generator
|
150 |
+
|
151 |
+
**Ever wanted to learn something new? Struggled to break down the concept to more digestible subconcepts? In this demo, we use <a href="https://cloud.sambanova.ai">SambaNova's</a> superfast LLama 3.2 3B and LLama 3.1 8B models to summarize the concept and subconcepts as well as provide a detailed lesson for each of the subconcepts.**
|
152 |
+
|
153 |
+
*To use this, follow the instructions below:*
|
154 |
+
|
155 |
+
1. Navigate to <a href="https://cloud.sambanova.ai">https://cloud.sambanova.ai</a>, login and copy your API Key
|
156 |
+
2. Paste it in the SambaNova API Key box below
|
157 |
+
3. Enter a concept you are interested in (e.g. Variational Autoencoders)
|
158 |
+
4. Choose the number of subconcepts you want to break your lessons into
|
159 |
+
5. Click 'Generate Lesson Plan'
|
160 |
+
6. Wait for a few seconds for multiple LLama 3B and 8B calls to finish
|
161 |
+
7. Read through and enjoy your lesson plans (Navigate to the tabs at the bottom)
|
162 |
""",
|
163 |
+
elem_id="header", container=True
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
164 |
)
|
165 |
|
166 |
with gr.Column():
|
|
|
173 |
|
174 |
with gr.Column():
|
175 |
progress_output = gr.Textbox(label="Progress", interactive=True)
|
176 |
+
lesson_intro = gr.Markdown(label="Lesson Intro", container=True)
|
177 |
|
178 |
tab_contents = []
|
179 |
|
180 |
with gr.Tabs() as tabs:
|
181 |
for i in range(MAX_SUBCONCEPTS): # Initial set of tabs
|
182 |
with gr.Tab(f"Lesson {i+1}", visible=False):
|
183 |
+
exec(f'tab_{i}=gr.Markdown(f"This is content for Lesson {i+1}", container=True)')
|
184 |
exec(f'tab_contents.append(tab_{i})')
|
185 |
|
186 |
generate_btn.click(
|