Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
|
@@ -1503,6 +1503,7 @@ with gr.Blocks(
|
|
| 1503 |
#chat-input-row {align-items: center !important;}
|
| 1504 |
.gradio-container { background-color: white !important; color: black !important;}
|
| 1505 |
main {max-width: fit-content !important}
|
|
|
|
| 1506 |
""",
|
| 1507 |
js=js_code,
|
| 1508 |
head='<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.15.4/css/all.min.css">'
|
|
@@ -1590,9 +1591,7 @@ with gr.Blocks(
|
|
| 1590 |
add_note_btn = gr.Button("+ Add note", elem_id="add-note-btn")
|
| 1591 |
study_guide_btn = gr.Button("Study Guide", elem_id="study-guide-btn")
|
| 1592 |
quiz_btn = gr.Button("Quiz Yourself", elem_id="quiz-btn")
|
| 1593 |
-
note_response = gr.Textbox(label="
|
| 1594 |
-
study_guide_response = gr.Textbox(label="Study Guide", visible=False)
|
| 1595 |
-
quiz_response = gr.Textbox(label="Quiz", visible=False)
|
| 1596 |
notes_list = gr.Dataframe(headers=["Title"], interactive=False, label="Your Notes", elem_id="notes-list")
|
| 1597 |
with gr.Column(visible=False) as note_editor:
|
| 1598 |
note_title = gr.Textbox(label="Note Title", elem_id="note-title")
|
|
@@ -1610,73 +1609,57 @@ with gr.Blocks(
|
|
| 1610 |
|
| 1611 |
# --- UI LOGIC FOR SHOWING/HIDING RESPONSE COMPONENTS ---
|
| 1612 |
def show_only(component):
|
| 1613 |
-
# Helper to show only the given response component
|
| 1614 |
return (
|
| 1615 |
gr.update(visible=(component == "note")),
|
| 1616 |
gr.update(visible=(component == "study")),
|
| 1617 |
gr.update(visible=(component == "quiz")),
|
| 1618 |
)
|
| 1619 |
|
| 1620 |
-
# Add Note button: generate note draft and show editor/response
|
| 1621 |
async def add_note_fn(notes, lecture_context, api_service, api_key, title_val, desc_val, style_val, audience_val):
|
| 1622 |
context = get_fallback_lecture_context(lecture_context, title_val, desc_val, style_val, audience_val)
|
| 1623 |
note = await run_note_agent(api_service, api_key, context, "", "")
|
| 1624 |
note_text = (note.get("title", "") + "\n" + note.get("content", "")).strip()
|
| 1625 |
return (
|
| 1626 |
-
gr.update(
|
| 1627 |
-
gr.update(visible=False, value=""),
|
| 1628 |
-
gr.update(visible=False, value=""),
|
| 1629 |
note.get("title", ""),
|
| 1630 |
note.get("content", "")
|
| 1631 |
)
|
| 1632 |
add_note_btn.click(
|
| 1633 |
fn=add_note_fn,
|
| 1634 |
inputs=[notes_state, lecture_context_state, api_service, api_key, title, lecture_content_description, lecture_style, lecture_type],
|
| 1635 |
-
outputs=[note_response,
|
| 1636 |
)
|
| 1637 |
|
| 1638 |
# Study Guide button: generate study guide and show response
|
| 1639 |
async def study_guide_btn_fn(notes, lecture_context, api_service, api_key, title_val, desc_val, style_val, audience_val):
|
| 1640 |
context = get_fallback_lecture_context(lecture_context, title_val, desc_val, style_val, audience_val)
|
| 1641 |
guide = await run_study_agent(api_service, api_key, context)
|
| 1642 |
-
return (
|
| 1643 |
-
gr.update(visible=False, value=""),
|
| 1644 |
-
gr.update(visible=True, value=guide),
|
| 1645 |
-
gr.update(visible=False, value="")
|
| 1646 |
-
)
|
| 1647 |
study_guide_btn.click(
|
| 1648 |
fn=study_guide_btn_fn,
|
| 1649 |
inputs=[notes_state, lecture_context_state, api_service, api_key, title, lecture_content_description, lecture_style, lecture_type],
|
| 1650 |
-
outputs=[note_response
|
| 1651 |
)
|
| 1652 |
|
| 1653 |
# Quiz button: generate quiz and show response
|
| 1654 |
async def quiz_btn_fn(notes, lecture_context, api_service, api_key, title_val, desc_val, style_val, audience_val):
|
| 1655 |
context = get_fallback_lecture_context(lecture_context, title_val, desc_val, style_val, audience_val)
|
| 1656 |
quiz = await run_quiz_agent(api_service, api_key, context)
|
| 1657 |
-
return (
|
| 1658 |
-
gr.update(visible=False, value=""),
|
| 1659 |
-
gr.update(visible=False, value=""),
|
| 1660 |
-
gr.update(visible=True, value=quiz)
|
| 1661 |
-
)
|
| 1662 |
quiz_btn.click(
|
| 1663 |
fn=quiz_btn_fn,
|
| 1664 |
inputs=[notes_state, lecture_context_state, api_service, api_key, title, lecture_content_description, lecture_style, lecture_type],
|
| 1665 |
-
outputs=[note_response
|
| 1666 |
)
|
| 1667 |
|
| 1668 |
-
# Back button:
|
| 1669 |
back_btn.click(
|
| 1670 |
-
fn=lambda: (
|
| 1671 |
-
gr.update(visible=False, value=""),
|
| 1672 |
-
gr.update(visible=False, value=""),
|
| 1673 |
-
gr.update(visible=False, value="")
|
| 1674 |
-
),
|
| 1675 |
inputs=[],
|
| 1676 |
-
outputs=[note_response
|
| 1677 |
)
|
| 1678 |
|
| 1679 |
-
# Save Note button: add note to state and update list,
|
| 1680 |
async def save_note(note_title_val, note_content_val, notes, lecture_context, api_service, api_key, note_type=None):
|
| 1681 |
note = await run_note_agent(api_service, api_key, get_fallback_lecture_context(lecture_context, note_title_val, note_content_val, "", ""), note_title_val, note_content_val)
|
| 1682 |
# Prefix title with note type if provided
|
|
@@ -1691,14 +1674,12 @@ with gr.Blocks(
|
|
| 1691 |
return (
|
| 1692 |
update_notes_list(new_notes),
|
| 1693 |
new_notes,
|
| 1694 |
-
gr.update(
|
| 1695 |
-
gr.update(visible=False, value=""),
|
| 1696 |
-
gr.update(visible=False, value="")
|
| 1697 |
)
|
| 1698 |
save_note_btn.click(
|
| 1699 |
fn=save_note,
|
| 1700 |
inputs=[note_title, note_content, notes_state, lecture_context_state, api_service, api_key],
|
| 1701 |
-
outputs=[notes_list, notes_state, note_response
|
| 1702 |
)
|
| 1703 |
|
| 1704 |
# --- CHAT AGENT LOGIC ---
|
|
@@ -1959,7 +1940,7 @@ with gr.Blocks(
|
|
| 1959 |
await asyncio.sleep(0.1)
|
| 1960 |
|
| 1961 |
# Process file and generate inputs
|
| 1962 |
-
yield html_with_progress("
|
| 1963 |
await asyncio.sleep(0.1)
|
| 1964 |
|
| 1965 |
result = await study_mode_process(file, api_service, api_key)
|
|
@@ -1967,7 +1948,7 @@ with gr.Blocks(
|
|
| 1967 |
# Show success message with updated inputs
|
| 1968 |
success_html = """
|
| 1969 |
<div style="display: flex; flex-direction: column; justify-content: center; align-items: center; height: 100%; min-height: 700px; padding: 20px; text-align: center; border: 1px solid #ddd; border-radius: 30px; box-shadow: 0 0 2rem rgba(0, 0, 0, .14) !important;">
|
| 1970 |
-
<h2 style="font-style: italic; color: #000 !important;">
|
| 1971 |
<p style="margin-top: 10px; font-size: 16px;color: #000">The form has been updated with the extracted information. Click Generate Lecture to proceed.</p>
|
| 1972 |
</div>
|
| 1973 |
"""
|
|
@@ -2217,8 +2198,8 @@ with gr.Blocks(
|
|
| 2217 |
if os.path.exists(note_file):
|
| 2218 |
with open(note_file, "r", encoding="utf-8") as f:
|
| 2219 |
note_text = f.read()
|
| 2220 |
-
return gr.update(
|
| 2221 |
-
return gr.update(
|
| 2222 |
notes_list.select(
|
| 2223 |
fn=show_note_content,
|
| 2224 |
inputs=[notes_state],
|
|
|
|
| 1503 |
#chat-input-row {align-items: center !important;}
|
| 1504 |
.gradio-container { background-color: white !important; color: black !important;}
|
| 1505 |
main {max-width: fit-content !important}
|
| 1506 |
+
#component-36 {height: 460px !important}
|
| 1507 |
""",
|
| 1508 |
js=js_code,
|
| 1509 |
head='<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.15.4/css/all.min.css">'
|
|
|
|
| 1591 |
add_note_btn = gr.Button("+ Add note", elem_id="add-note-btn")
|
| 1592 |
study_guide_btn = gr.Button("Study Guide", elem_id="study-guide-btn")
|
| 1593 |
quiz_btn = gr.Button("Quiz Yourself", elem_id="quiz-btn")
|
| 1594 |
+
note_response = gr.Textbox(label="Response", visible=True, value="Your notes, study guides, and quizzes will appear here...")
|
|
|
|
|
|
|
| 1595 |
notes_list = gr.Dataframe(headers=["Title"], interactive=False, label="Your Notes", elem_id="notes-list")
|
| 1596 |
with gr.Column(visible=False) as note_editor:
|
| 1597 |
note_title = gr.Textbox(label="Note Title", elem_id="note-title")
|
|
|
|
| 1609 |
|
| 1610 |
# --- UI LOGIC FOR SHOWING/HIDING RESPONSE COMPONENTS ---
|
| 1611 |
def show_only(component):
|
|
|
|
| 1612 |
return (
|
| 1613 |
gr.update(visible=(component == "note")),
|
| 1614 |
gr.update(visible=(component == "study")),
|
| 1615 |
gr.update(visible=(component == "quiz")),
|
| 1616 |
)
|
| 1617 |
|
|
|
|
| 1618 |
async def add_note_fn(notes, lecture_context, api_service, api_key, title_val, desc_val, style_val, audience_val):
|
| 1619 |
context = get_fallback_lecture_context(lecture_context, title_val, desc_val, style_val, audience_val)
|
| 1620 |
note = await run_note_agent(api_service, api_key, context, "", "")
|
| 1621 |
note_text = (note.get("title", "") + "\n" + note.get("content", "")).strip()
|
| 1622 |
return (
|
| 1623 |
+
gr.update(value=note_text),
|
|
|
|
|
|
|
| 1624 |
note.get("title", ""),
|
| 1625 |
note.get("content", "")
|
| 1626 |
)
|
| 1627 |
add_note_btn.click(
|
| 1628 |
fn=add_note_fn,
|
| 1629 |
inputs=[notes_state, lecture_context_state, api_service, api_key, title, lecture_content_description, lecture_style, lecture_type],
|
| 1630 |
+
outputs=[note_response, note_title, note_content]
|
| 1631 |
)
|
| 1632 |
|
| 1633 |
# Study Guide button: generate study guide and show response
|
| 1634 |
async def study_guide_btn_fn(notes, lecture_context, api_service, api_key, title_val, desc_val, style_val, audience_val):
|
| 1635 |
context = get_fallback_lecture_context(lecture_context, title_val, desc_val, style_val, audience_val)
|
| 1636 |
guide = await run_study_agent(api_service, api_key, context)
|
| 1637 |
+
return gr.update(value=guide)
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1638 |
study_guide_btn.click(
|
| 1639 |
fn=study_guide_btn_fn,
|
| 1640 |
inputs=[notes_state, lecture_context_state, api_service, api_key, title, lecture_content_description, lecture_style, lecture_type],
|
| 1641 |
+
outputs=[note_response]
|
| 1642 |
)
|
| 1643 |
|
| 1644 |
# Quiz button: generate quiz and show response
|
| 1645 |
async def quiz_btn_fn(notes, lecture_context, api_service, api_key, title_val, desc_val, style_val, audience_val):
|
| 1646 |
context = get_fallback_lecture_context(lecture_context, title_val, desc_val, style_val, audience_val)
|
| 1647 |
quiz = await run_quiz_agent(api_service, api_key, context)
|
| 1648 |
+
return gr.update(value=quiz)
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1649 |
quiz_btn.click(
|
| 1650 |
fn=quiz_btn_fn,
|
| 1651 |
inputs=[notes_state, lecture_context_state, api_service, api_key, title, lecture_content_description, lecture_style, lecture_type],
|
| 1652 |
+
outputs=[note_response]
|
| 1653 |
)
|
| 1654 |
|
| 1655 |
+
# Back button: clear response
|
| 1656 |
back_btn.click(
|
| 1657 |
+
fn=lambda: gr.update(value="Click any button above to generate content..."),
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1658 |
inputs=[],
|
| 1659 |
+
outputs=[note_response]
|
| 1660 |
)
|
| 1661 |
|
| 1662 |
+
# Save Note button: add note to state and update list, clear response
|
| 1663 |
async def save_note(note_title_val, note_content_val, notes, lecture_context, api_service, api_key, note_type=None):
|
| 1664 |
note = await run_note_agent(api_service, api_key, get_fallback_lecture_context(lecture_context, note_title_val, note_content_val, "", ""), note_title_val, note_content_val)
|
| 1665 |
# Prefix title with note type if provided
|
|
|
|
| 1674 |
return (
|
| 1675 |
update_notes_list(new_notes),
|
| 1676 |
new_notes,
|
| 1677 |
+
gr.update(value="Click any button above to generate content...")
|
|
|
|
|
|
|
| 1678 |
)
|
| 1679 |
save_note_btn.click(
|
| 1680 |
fn=save_note,
|
| 1681 |
inputs=[note_title, note_content, notes_state, lecture_context_state, api_service, api_key],
|
| 1682 |
+
outputs=[notes_list, notes_state, note_response]
|
| 1683 |
)
|
| 1684 |
|
| 1685 |
# --- CHAT AGENT LOGIC ---
|
|
|
|
| 1940 |
await asyncio.sleep(0.1)
|
| 1941 |
|
| 1942 |
# Process file and generate inputs
|
| 1943 |
+
yield html_with_progress("Researching lecture material...", 75), None, None
|
| 1944 |
await asyncio.sleep(0.1)
|
| 1945 |
|
| 1946 |
result = await study_mode_process(file, api_service, api_key)
|
|
|
|
| 1948 |
# Show success message with updated inputs
|
| 1949 |
success_html = """
|
| 1950 |
<div style="display: flex; flex-direction: column; justify-content: center; align-items: center; height: 100%; min-height: 700px; padding: 20px; text-align: center; border: 1px solid #ddd; border-radius: 30px; box-shadow: 0 0 2rem rgba(0, 0, 0, .14) !important;">
|
| 1951 |
+
<h2 style="font-style: italic; color: #000 !important;">Research on study material completed, you can now generate lecture</h2>
|
| 1952 |
<p style="margin-top: 10px; font-size: 16px;color: #000">The form has been updated with the extracted information. Click Generate Lecture to proceed.</p>
|
| 1953 |
</div>
|
| 1954 |
"""
|
|
|
|
| 2198 |
if os.path.exists(note_file):
|
| 2199 |
with open(note_file, "r", encoding="utf-8") as f:
|
| 2200 |
note_text = f.read()
|
| 2201 |
+
return gr.update(value=note_text)
|
| 2202 |
+
return gr.update(value="Click any button above to generate content...")
|
| 2203 |
notes_list.select(
|
| 2204 |
fn=show_note_content,
|
| 2205 |
inputs=[notes_state],
|