Upload 3 files
Browse files- app.py +62 -13
- config.json +5 -6
- requirements.txt +1 -1
app.py
CHANGED
@@ -10,13 +10,60 @@ import urllib.parse
|
|
10 |
|
11 |
|
12 |
# Configuration
|
13 |
-
SPACE_NAME = "
|
14 |
SPACE_DESCRIPTION = ""
|
15 |
-
SYSTEM_PROMPT = """You are a
|
16 |
-
|
17 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
18 |
# Get access code from environment variable for security
|
19 |
-
|
|
|
20 |
ENABLE_DYNAMIC_URLS = True
|
21 |
|
22 |
# Get API key from environment - customizable variable name with validation
|
@@ -154,7 +201,9 @@ def get_grounding_context():
|
|
154 |
for i, url in enumerate(GROUNDING_URLS, 1):
|
155 |
if url.strip():
|
156 |
content = fetch_url_content(url.strip())
|
157 |
-
|
|
|
|
|
158 |
|
159 |
if context_parts:
|
160 |
result = "\n\n" + "\n\n".join(context_parts) + "\n\n"
|
@@ -383,7 +432,7 @@ _access_granted_global = False # Global fallback
|
|
383 |
def verify_access_code(code):
|
384 |
"""Verify the access code"""
|
385 |
global _access_granted_global
|
386 |
-
if
|
387 |
_access_granted_global = True
|
388 |
return gr.update(visible=False), gr.update(visible=True), gr.update(value=True)
|
389 |
|
@@ -397,7 +446,7 @@ def verify_access_code(code):
|
|
397 |
def protected_generate_response(message, history):
|
398 |
"""Protected response function that checks access"""
|
399 |
# Check if access is granted via the global variable
|
400 |
-
if ACCESS_CODE and not _access_granted_global:
|
401 |
return "Please enter the access code to continue."
|
402 |
return generate_response(message, history)
|
403 |
|
@@ -474,7 +523,7 @@ def get_configuration_status():
|
|
474 |
if ENABLE_DYNAMIC_URLS:
|
475 |
status_parts.append("π **Dynamic URLs:** Enabled")
|
476 |
|
477 |
-
if ACCESS_CODE:
|
478 |
status_parts.append("π **Access Control:** Enabled")
|
479 |
else:
|
480 |
status_parts.append("π **Access:** Public")
|
@@ -491,7 +540,7 @@ with gr.Blocks(title=SPACE_NAME) as demo:
|
|
491 |
gr.Markdown(get_configuration_status())
|
492 |
|
493 |
# Access code section (shown only if ACCESS_CODE is set)
|
494 |
-
with gr.Column(visible=
|
495 |
gr.Markdown("### π Access Required")
|
496 |
gr.Markdown("Please enter the access code provided by your instructor:")
|
497 |
|
@@ -504,12 +553,12 @@ with gr.Blocks(title=SPACE_NAME) as demo:
|
|
504 |
access_error = gr.Markdown(visible=False)
|
505 |
|
506 |
# Main chat interface (hidden until access granted)
|
507 |
-
with gr.Column(visible=
|
508 |
chat_interface = gr.ChatInterface(
|
509 |
fn=store_and_generate_response, # Use wrapper function to store history
|
510 |
title="", # Title already shown above
|
511 |
description="", # Description already shown above
|
512 |
-
examples=['
|
513 |
type="messages" # Use modern message format for better compatibility
|
514 |
)
|
515 |
|
@@ -525,7 +574,7 @@ with gr.Blocks(title=SPACE_NAME) as demo:
|
|
525 |
)
|
526 |
|
527 |
# Connect access verification
|
528 |
-
if ACCESS_CODE:
|
529 |
access_btn.click(
|
530 |
verify_access_code,
|
531 |
inputs=[access_input],
|
|
|
10 |
|
11 |
|
12 |
# Configuration
|
13 |
+
SPACE_NAME = "CCNY 10800 Support"
|
14 |
SPACE_DESCRIPTION = ""
|
15 |
+
SYSTEM_PROMPT = """You are a supportive course assistant for Professor Zach Muhlbauer's Foundations of Data Science course (CSC 10800 R) at City College of New York.
|
16 |
+
|
17 |
+
Core Responsibilities
|
18 |
+
* Course Navigation: Help students locate and understand syllabus information, assignment details, schedules, readings, and course materials
|
19 |
+
* Learning Facilitation: Guide students toward understanding concepts through Socratic questioning and scaffolding rather than providing direct answers
|
20 |
+
* Administrative Support: Provide accurate information about deadlines, exam dates, office hours, and course policies
|
21 |
+
|
22 |
+
Response Guidelines
|
23 |
+
* Precision First: Be exact with all dates, times, deadlines, and scheduling information
|
24 |
+
* Warm Tone: Use encouraging, supportive language that builds student confidence
|
25 |
+
* Pedagogical Approach: Never provide direct answers to assignments or assessments; instead, ask guiding questions that help students discover solutions independently
|
26 |
+
* Scope Boundaries: Only address questions related to this specific course (CSC 10800 R) - syllabus, schedule, assignments, readings, and general data science learning support
|
27 |
+
* Specific Protocols: For questions about grades, redirect students to contact Professor Muhlbauer at the email provided in the course materials for all related inquiries: [email protected]
|
28 |
+
|
29 |
+
For Assignment Help:
|
30 |
+
* Ask clarifying questions about what specific aspect they're struggling with
|
31 |
+
* Guide them to relevant course materials or resources
|
32 |
+
* Use the {{Code Executor (Python)}} tool to demonstrate concepts or debugging approaches
|
33 |
+
* Encourage them to break down problems into smaller, manageable steps
|
34 |
+
* Suggest review of relevant readings or lecture materials
|
35 |
+
|
36 |
+
For Scheduling/Deadlines:
|
37 |
+
* Always cross-reference the most current course schedule
|
38 |
+
* Provide specific dates and times
|
39 |
+
* Remind students of upcoming deadlines proactively when relevant
|
40 |
+
* NB: If {{today}} is after the last date of the course, then do NOT make up new dates based on Tue/Thu schedule of the class
|
41 |
+
|
42 |
+
For Conceptual Questions:
|
43 |
+
* Use Socratic method to guide discovery
|
44 |
+
* Provide analogies or real-world applications to clarify abstract concepts
|
45 |
+
* Reference specific course materials where students can find more information
|
46 |
+
* Encourage active engagement with the material
|
47 |
+
|
48 |
+
Uncertainty Protocol:
|
49 |
+
When uncertain about any information:
|
50 |
+
* Explicitly state your uncertainty
|
51 |
+
* Direct students to verify information through official course materials
|
52 |
+
* Suggest contacting Professor Muhlbauer for clarification
|
53 |
+
* Provide general guidance on where to find authoritative information
|
54 |
+
|
55 |
+
Engagement Style:
|
56 |
+
* Begin responses with acknowledgment of the student's question
|
57 |
+
* Use warm, encouraging language
|
58 |
+
* Ask follow-up questions to better understand student needs
|
59 |
+
* Celebrate student progress and effort
|
60 |
+
|
61 |
+
Remember: Your goal is to support student learning and success while maintaining the pedagogical integrity of the course. You are a learning facilitator, not an answer provider."""
|
62 |
+
MODEL = "google/gemini-2.0-flash-001"
|
63 |
+
GROUNDING_URLS = ["https://zmuhls.github.io/ccny-data-science/schedule/", "https://zmuhls.github.io/ccny-data-science/syllabus/", "https://zmuhls.github.io/ccny-data-science/activities/", "https://zmuhls.github.io/ccny-data-science/portfolio/"]
|
64 |
# Get access code from environment variable for security
|
65 |
+
# If SPACE_ACCESS_CODE is not set, no access control is applied
|
66 |
+
ACCESS_CODE = os.environ.get("SPACE_ACCESS_CODE")
|
67 |
ENABLE_DYNAMIC_URLS = True
|
68 |
|
69 |
# Get API key from environment - customizable variable name with validation
|
|
|
201 |
for i, url in enumerate(GROUNDING_URLS, 1):
|
202 |
if url.strip():
|
203 |
content = fetch_url_content(url.strip())
|
204 |
+
# Add priority indicators
|
205 |
+
priority_label = "PRIMARY" if i <= 2 else "SECONDARY"
|
206 |
+
context_parts.append(f"[{priority_label}] Context from URL {{i}} ({{url}}):{{content}}")
|
207 |
|
208 |
if context_parts:
|
209 |
result = "\n\n" + "\n\n".join(context_parts) + "\n\n"
|
|
|
432 |
def verify_access_code(code):
|
433 |
"""Verify the access code"""
|
434 |
global _access_granted_global
|
435 |
+
if ACCESS_CODE is None:
|
436 |
_access_granted_global = True
|
437 |
return gr.update(visible=False), gr.update(visible=True), gr.update(value=True)
|
438 |
|
|
|
446 |
def protected_generate_response(message, history):
|
447 |
"""Protected response function that checks access"""
|
448 |
# Check if access is granted via the global variable
|
449 |
+
if ACCESS_CODE is not None and not _access_granted_global:
|
450 |
return "Please enter the access code to continue."
|
451 |
return generate_response(message, history)
|
452 |
|
|
|
523 |
if ENABLE_DYNAMIC_URLS:
|
524 |
status_parts.append("π **Dynamic URLs:** Enabled")
|
525 |
|
526 |
+
if ACCESS_CODE is not None:
|
527 |
status_parts.append("π **Access Control:** Enabled")
|
528 |
else:
|
529 |
status_parts.append("π **Access:** Public")
|
|
|
540 |
gr.Markdown(get_configuration_status())
|
541 |
|
542 |
# Access code section (shown only if ACCESS_CODE is set)
|
543 |
+
with gr.Column(visible=(ACCESS_CODE is not None)) as access_section:
|
544 |
gr.Markdown("### π Access Required")
|
545 |
gr.Markdown("Please enter the access code provided by your instructor:")
|
546 |
|
|
|
553 |
access_error = gr.Markdown(visible=False)
|
554 |
|
555 |
# Main chat interface (hidden until access granted)
|
556 |
+
with gr.Column(visible=(ACCESS_CODE is None)) as chat_section:
|
557 |
chat_interface = gr.ChatInterface(
|
558 |
fn=store_and_generate_response, # Use wrapper function to store history
|
559 |
title="", # Title already shown above
|
560 |
description="", # Description already shown above
|
561 |
+
examples=['When is the social coding portfolio due?'],
|
562 |
type="messages" # Use modern message format for better compatibility
|
563 |
)
|
564 |
|
|
|
574 |
)
|
575 |
|
576 |
# Connect access verification
|
577 |
+
if ACCESS_CODE is not None:
|
578 |
access_btn.click(
|
579 |
verify_access_code,
|
580 |
inputs=[access_input],
|
config.json
CHANGED
@@ -1,13 +1,12 @@
|
|
1 |
{
|
2 |
-
"name": "
|
3 |
"description": "",
|
4 |
-
"system_prompt": "You are a
|
5 |
-
"model": "
|
6 |
"api_key_var": "OPENROUTER_API_KEY",
|
7 |
"temperature": 0.7,
|
8 |
"max_tokens": 750,
|
9 |
-
"examples": "['
|
10 |
-
"grounding_urls": "[\"https://
|
11 |
-
"access_code": "",
|
12 |
"enable_dynamic_urls": true
|
13 |
}
|
|
|
1 |
{
|
2 |
+
"name": "CCNY 10800 Support",
|
3 |
"description": "",
|
4 |
+
"system_prompt": "You are a supportive course assistant for Professor Zach Muhlbauer's Foundations of Data Science course (CSC 10800 R) at City College of New York.\n\nCore Responsibilities\n* Course Navigation: Help students locate and understand syllabus information, assignment details, schedules, readings, and course materials\n* Learning Facilitation: Guide students toward understanding concepts through Socratic questioning and scaffolding rather than providing direct answers\n* Administrative Support: Provide accurate information about deadlines, exam dates, office hours, and course policies\n\nResponse Guidelines\n* Precision First: Be exact with all dates, times, deadlines, and scheduling information\n* Warm Tone: Use encouraging, supportive language that builds student confidence\n* Pedagogical Approach: Never provide direct answers to assignments or assessments; instead, ask guiding questions that help students discover solutions independently\n* Scope Boundaries: Only address questions related to this specific course (CSC 10800 R) - syllabus, schedule, assignments, readings, and general data science learning support\n* Specific Protocols: For questions about grades, redirect students to contact Professor Muhlbauer at the email provided in the course materials for all related inquiries: zmuhlbauer@ccny.cuny.edu\n\nFor Assignment Help:\n* Ask clarifying questions about what specific aspect they're struggling with\n* Guide them to relevant course materials or resources\n* Use the {{Code Executor (Python)}} tool to demonstrate concepts or debugging approaches\n* Encourage them to break down problems into smaller, manageable steps\n* Suggest review of relevant readings or lecture materials\n\nFor Scheduling/Deadlines:\n* Always cross-reference the most current course schedule\n* Provide specific dates and times\n* Remind students of upcoming deadlines proactively when relevant\n* NB: If {{today}} is after the last date of the course, then do NOT make up new dates based on Tue/Thu schedule of the class\n\nFor Conceptual Questions:\n* Use Socratic method to guide discovery\n* Provide analogies or real-world applications to clarify abstract concepts\n* Reference specific course materials where students can find more information\n* Encourage active engagement with the material\n\nUncertainty Protocol:\nWhen uncertain about any information:\n* Explicitly state your uncertainty\n* Direct students to verify information through official course materials\n* Suggest contacting Professor Muhlbauer for clarification\n* Provide general guidance on where to find authoritative information\n\nEngagement Style:\n* Begin responses with acknowledgment of the student's question\n* Use warm, encouraging language\n* Ask follow-up questions to better understand student needs\n* Celebrate student progress and effort\n\nRemember: Your goal is to support student learning and success while maintaining the pedagogical integrity of the course. You are a learning facilitator, not an answer provider.",
|
5 |
+
"model": "google/gemini-2.0-flash-001",
|
6 |
"api_key_var": "OPENROUTER_API_KEY",
|
7 |
"temperature": 0.7,
|
8 |
"max_tokens": 750,
|
9 |
+
"examples": "['When is the social coding portfolio due?']",
|
10 |
+
"grounding_urls": "[\"https://zmuhls.github.io/ccny-data-science/schedule/\", \"https://zmuhls.github.io/ccny-data-science/syllabus/\", \"https://zmuhls.github.io/ccny-data-science/activities/\", \"https://zmuhls.github.io/ccny-data-science/portfolio/\"]",
|
|
|
11 |
"enable_dynamic_urls": true
|
12 |
}
|
requirements.txt
CHANGED
@@ -1,4 +1,4 @@
|
|
1 |
-
gradio>=
|
2 |
requests>=2.32.3
|
3 |
beautifulsoup4>=4.12.3
|
4 |
python-dotenv>=1.0.0
|
|
|
1 |
+
gradio>=5.0.0
|
2 |
requests>=2.32.3
|
3 |
beautifulsoup4>=4.12.3
|
4 |
python-dotenv>=1.0.0
|